Solved

What's wrong with this code?

Posted on 2008-06-24
11
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 143

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 143

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

734 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