Brian
asked on
What's wrong with this code?
I must be not doing something right. I've got a combo box listing values from a table. Each value corresponds to a different form. When the user makes his selection he presses a button that opens the appropriate form based on which value was selected.
Here's where I started:
Private Sub Command8_Click()
Dim stForm1 As String
Dim stForm2 As String
Dim stForm3 As String
Dim stForm4 As String
stForm1 = "EngForm"
If [Me.combo5.text] = "Engineering" Then
DoCmd.OpenForm stForm1
Else
End If
End Sub
Seems like it should work to me but I'm somewhat of a beginner.
Here's where I started:
Private Sub Command8_Click()
Dim stForm1 As String
Dim stForm2 As String
Dim stForm3 As String
Dim stForm4 As String
stForm1 = "EngForm"
If [Me.combo5.text] = "Engineering" Then
DoCmd.OpenForm stForm1
Else
End If
End Sub
Seems like it should work to me but I'm somewhat of a beginner.
ASKER
I tried that first. Couldn't get it to work.
I should have been more specific about the error I'm getting.
Run-time error '2465':
Microsoft Access can't find the field '|' referred to in your expression.
Mind you, all the field and form names are correct in the code.
I should have been more specific about the error I'm getting.
Run-time error '2465':
Microsoft Access can't find the field '|' referred to in your expression.
Mind you, all the field and form names are correct in the code.
ASKER
Ok, scratch that. When I remove the brackets error I get is this:
Run-time error '2185':
You can't reference a property or method for a control unless the control has the focus.
Run-time error '2185':
You can't reference a property or method for a control unless the control has the focus.
ok. try to use .Value instead of .Text
Is this VB6 or VBA or ...?
VB6
Dim fTemp As Form
Set fTemp = Forms("EngForm")
fTemp.Show
Dim fTemp As Form
Set fTemp = Forms("EngForm")
fTemp.Show
ASKER
VBA
So, is this a combobox on a userform or on a sheet?
There is no need to use a variable as I see in your example
If [Me.combo5.text] = "Engineering" Then
DoCmd.OpenForm "EngForm"
End if
If [Me.combo5.text] = "Engineering" Then
DoCmd.OpenForm "EngForm"
End if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
3S got it. Thanks for the help!!
is wrong...
this should work better
If Me.combo5.text = "Engineering" Then