Share via

Using Custom Properties

Anonymous
2020-01-07T21:59:36+00:00

Hi

I dont know if this is the easiest or best method to do what I am wanting to do.  In fact I think its probably not.  But it is a good opportunity to get my head around this concept with a fairly simple idea.

I struggle with understanding properties and class modules.  I guess I shouldnt, after all i have been using Access a long time now...but nonethelesss I am confused by this.

In looking it seems simple enough.

make a class

In the class set a property or let a property

In the class get the property

I think I have this bit under control.

I decided as I dont get it, it would be a good idea to create a generic form with 20 fields.  Then set a property for the tablename I am passing to the form, I am already using the openArgs for the recordID.  I know there are a myriad of other ways to do this.  I am not interested in that.  I am wanting to learn properties so this seems a simple enough idea to work with.

However something is missing in my brain or something...

I have the following in my class

Private mFormName As String

Public Property Let cssFormName(Value As String)

'This property allows reuse of the same form for

'any table

    mFormName = Value

End Property

Public Property Get cssGetFormName() As String

    cssGetFormName = mFormName

End Property

Then in the form intiating the open event I have

Dim pFormName As clsFormName

    Set pFormName = New clsFormName

    pFormName.cssFormName = strForm

As I read it this will send the value passed in as strForm (silly name, but it will do for now) over to the class and into the property.

I then open the target form and would think I can just read the value back from pformName...but I cant.  Access is telling me I have to declare clsFormName again, which if I do is refusing to give me back a value at all.  I figure as I am bashing my way through this I am missing something conceptually and this is why i am struggling.

Amongst my madness methods I am thinking...Do I need to declare the class clsFormName as a public or global variable in the Class?  Do I need to declare it somewhere in one of my support modules?  Why cant I just go msgbox pFormName.cssGetFormName in the target form and retrieve the property?

I am so lost on this, been looking at tutorials and pages of stuff and still dont get it.  Maybe I am being too simple...or too complex ...or ???????

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
2020-01-07T23:30:37+00:00

You would create a Standard Module, and then declare it there, using Public:

Public g_pFormName As clsFormName

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2020-01-07T23:12:47+00:00

    How would I declare it project wide?  Sorry if this is obvious...this is obviously a hole in my head where my thoughts run out.

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2020-01-07T22:03:37+00:00

    It's a matter of Scope.

    pFormName is only valid within the Form_Open event.

    Move the declaration to the Declarations section of the form, and you can use it from any event in that form.

    Was this answer helpful?

    0 comments No comments