Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What's wrong with this code?

Posted on 2008-06-24
11
Medium Priority
?
178 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

688 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