Referencing a form using a variable for it's name (1 Viewer)

ListO

Señor Member
Local time
Today, 15:10
Joined
Feb 2, 2000
Messages
162
Greetings to all

I've searched and hunted and experimented, but to no avail...

From a pop-up form, I would like to update the property of a label on one of several other forms. The circumstances of the moment will determine which form's label is getting updated.

I can't figure out how to reference a form using a variable name. The code I'd like to use is something like
Code:
Private Sub Cant_Figure_This()
Dim strFrmName as string

(various code which changes the value of 
strFrmName to be the name of a particular 
form which I want to alter)

Forms!strFrmName.Label1.Visible = True

End Sub
Unfortunately, Access wants strFormName to be the literal name of the form, not a variable which contains the name. I've tried using
Code:
Dim FrmName as Form, strFrmName as String

FormName = Forms!strFrmName
This doesn't work any better, and I can't figure how to assign a varying name to that form.

Am I asking the impossible?
 
Last edited:

casey

Registered User.
Local time
Today, 15:10
Joined
Dec 5, 2000
Messages
448
I've used something like the following to reference controls...

Me(strFormName)

Maybe you could try a variation of the following...

Forms(strFormName)Label11.Visible
 

ListO

Señor Member
Local time
Today, 15:10
Joined
Feb 2, 2000
Messages
162
It looked as if it would work, but...

It compiles OK, but then at runtime it gives an error:

Runtime error '2465':

Application-defined or object-defined error.

And not only that, it doesn't change the property!
 

casey

Registered User.
Local time
Today, 15:10
Joined
Dec 5, 2000
Messages
448
If it's not recognizing the control reference then it's not going to change the property either.

Other than a little bit of tweaking that should work!

I noticed that my references were not exactly the same as yours(double-check your variable names and what not). I might be missing something too.

Also, try...

Forms(trim(strFrmName))Label11.Visible = true

Hopefully someone can point out what I'm missing. Sorry I couldn't be of more help. Gotta go.
 

casey

Registered User.
Local time
Today, 15:10
Joined
Dec 5, 2000
Messages
448
Sorry that I didin't see this sooner, but in case you haven't got it yet try...

Forms(Ltrim(strFrmName)).Label11.Visible = True

I'm not exactly positive about it, but that should work.
 

casey

Registered User.
Local time
Today, 15:10
Joined
Dec 5, 2000
Messages
448
Sorry that I didin't see this sooner, but in case you haven't got it yet try...

Forms(Ltrim(strFrmName)).Label11.Visible = True

I'm not exactly positive about it, but that should work.
 

Users who are viewing this thread

Top Bottom