Solved

What's wrong with this code?

Posted on 2008-06-24
11
173 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:Haze0830
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21859612
   If [Me.combo5.text] = "Engineering" Then
is wrong...

this should work better
    If Me.combo5.text = "Engineering" Then
0
 
LVL 2

Author Comment

by:Haze0830
ID: 21859781
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
 
LVL 2

Author Comment

by:Haze0830
ID: 21859795
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21859923
ok. try to use .Value instead of .Text
0
 
LVL 7

Expert Comment

by:TRobinJames
ID: 21859931
Is this VB6 or VBA or ...?
0
 
LVL 10

Expert Comment

by:3_S
ID: 21860047
VB6
    Dim fTemp As Form
    Set fTemp = Forms("EngForm")
    fTemp.Show
0
 
LVL 2

Author Comment

by:Haze0830
ID: 21860259
VBA
0
 
LVL 7

Expert Comment

by:TRobinJames
ID: 21860290
So, is this a combobox on a userform or on a sheet?
0
 
LVL 10

Expert Comment

by:3_S
ID: 21860401
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
 
LVL 10

Accepted Solution

by:
3_S earned 250 total points
ID: 21860446
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
 
LVL 2

Author Comment

by:Haze0830
ID: 21864838
3S got it. Thanks for the help!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question