Use a variable for a form name

RaunLGoode

Registered User.
Local time
Today, 14:29
Joined
Feb 18, 2004
Messages
122
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,
 
a string is fine.

Docmd.OpenForm "strVariable"

Code:
    Dim strFormName As String
    strFormName = "Form2"
 
    DoCmd.OpenForm strFormName
 
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.

Code:
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
 
Last edited:
sry, didn't notice.
 

Users who are viewing this thread

Back
Top Bottom