View Full Version : Use a variable for a form name


RaunLGoode
10-01-2009, 02:31 PM
I have a form where the user selects 1 of 4 options. ( A through D)
Depending on the Users selection, a value is stored that is a literal match to the name of one of four forms ( frmA, frmB, etc)
Right now the variable is declared as a string (FormName)

What I want to do is "Show" the correct form using this variable
ie:
FormName.Show
etc...
FormName.Hide

This doesn't work.
Could some more experianced mind tell me what the proper way to do this would be, including what type of variable to declare?

I can't be the first person to try to do this

Thank you,

wazz
10-01-2009, 11:07 PM
a string is fine.

Docmd.OpenForm "strVariable"

Dim strFormName As String
strFormName = "Form2"

DoCmd.OpenForm strFormName

chergh
10-02-2009, 12:15 AM
This is excel so docmd won't work.

This is actually a bit of a pain to do, I was expecting it to be quite simple but it wasn't as easy as I thought.

As you're getting the form you want to open from a string it would appear you will need to use a select case statement or similar to do this.




Select Case UserForm1.controlName.value 'This looks at the value selected by your user in the other form change it to match what you have

Case is = "frmA"
frmA.show

case is = "frmB"
frmB.show

Case is = "frmC"
frmC.show

Case is = "frmD"
frmD.show

end select

wazz
10-02-2009, 12:57 AM
sry, didn't notice.