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.
LVL 2
Haze0830Asked:
Who is Participating?
 
3_SCommented:
Sorry wasn't reading your question correctly

    stform1 = "EngForm"
    Me.combo5.SetFocus
    If Me.combo5.Text = "Engineering" Then
            DoCmd.OpenForm stform1
    Else
    End If
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
   If [Me.combo5.text] = "Engineering" Then
is wrong...

this should work better
    If Me.combo5.text = "Engineering" Then
0
 
Haze0830Author Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Haze0830Author Commented:
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.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ok. try to use .Value instead of .Text
0
 
TRobinJamesCommented:
Is this VB6 or VBA or ...?
0
 
3_SCommented:
VB6
    Dim fTemp As Form
    Set fTemp = Forms("EngForm")
    fTemp.Show
0
 
Haze0830Author Commented:
VBA
0
 
TRobinJamesCommented:
So, is this a combobox on a userform or on a sheet?
0
 
3_SCommented:
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
0
 
Haze0830Author Commented:
3S got it. Thanks for the help!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.