Solved

What's wrong with this code?

Posted on 2008-06-24
11
174 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 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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