How to: If answer is X then go to Y, if not go to Z (1 Viewer)

Winkypop

Access Tard
Local time
Tomorrow, 00:57
Joined
Apr 13, 2005
Messages
8
I have a basic Access Form that contains a small number of questions.

Question 4 is a Yes / No combo box

  • If the user enters Yes, I want the focus to go to Question 5
  • If the user enters No, I want the focus to jump to Question 4.1
  • Completing question 4.1 will take the focus to question 5

I'll be hornswaggled if I can figure out how to do this.

I would love someone to help me out!

:confused:
 

RichO

Registered Yoozer
Local time
Today, 11:57
Joined
Jan 14, 2004
Messages
1,036
First you want to make sure your Tab Order is set up to follow the questions in the correct order. I would assume you've done this.

You would need to put a piece of VB code in the After Update event of your question combo like:

Code:
If Me.cboQuestion4 = "Yes" Then
     Me.Question5.SetFocus
End If

No "Else" condition is needed if the tab order takes you to question 4.1 after question 4.
 
Last edited:

Winkypop

Access Tard
Local time
Tomorrow, 00:57
Joined
Apr 13, 2005
Messages
8
Thanks RichO

Thanks!

Your advice and code makes perfect sense to me but I get an error when running the code. :confused:

I have Access 97, is that a problem?

I have opened the Properties for the Question4 combo, opened the Event tab, opened to the After Update option, clicked on the .... and selected Code Builder and OK

I pasted in your code. Upon running it I get the error:

Compile error:


Method or data member not found.​

The full code looks something like this:

Private Sub Question4_AfterUpdate()
If Me.cboQuestion4 = "Yes" Then
Me.Location.SetFocus
End If



NB
Question 4 = Question4
Question 5 = Location
 

RichO

Registered Yoozer
Local time
Today, 11:57
Joined
Jan 14, 2004
Messages
1,036
I used "cboQuestion4" as a sample name for your combo box. From your code it appears that the combo box is simply named "Question4", so remove the "cbo" and it should work.
 

modest

Registered User.
Local time
Today, 12:57
Joined
Jan 4, 2005
Messages
1,220
Just so he's not confused:

Code:
Private Sub Question4_AfterUpdate()

    If Me.Question4 = "Yes" Then
        Me.Location.SetFocus
    End If


Though I might try:
Code:
Private Sub Question4_AfterUpdate()
    
    Me.Question4.SetFocus                  [COLOR=Green]'this is so you can use the .text property[/COLOR]
    If Me.Question4.Text = "Yes" Then
        Me.Location.SetFocus
    End If
or
Code:
Private Sub Question4_AfterUpdate()

    If Me.Question4.Value = "Yes" Then
        Me.Location.SetFocus
    End If
 
Last edited:

Winkypop

Access Tard
Local time
Tomorrow, 00:57
Joined
Apr 13, 2005
Messages
8
We have a winner!!!

RichO

Fantastic!!!

I owe you a beer next time I am in Wisconsin!!!

What's your favourite, local or imported?

Cheers

Winkypop

:D
 

Winkypop

Access Tard
Local time
Tomorrow, 00:57
Joined
Apr 13, 2005
Messages
8
modest said:
You can email me one :)

Thanks dude.

OK, open your CD tray in a few minutes for a stream of Australia's finest ale

;)
 

Winkypop

Access Tard
Local time
Tomorrow, 00:57
Joined
Apr 13, 2005
Messages
8
Next Question

Ok guys, you have been great to me.

How do I automatically advance to the next TAB when ANY answer is selected from a combo box.

That is, the user does not need to press ENTER or TAB to advance.

Cheers !
 

modest

Registered User.
Local time
Today, 12:57
Joined
Jan 4, 2005
Messages
1,220
what is the "tab".. do you mean textbox?
 

RichO

Registered Yoozer
Local time
Today, 11:57
Joined
Jan 14, 2004
Messages
1,036
The AutoTab feature is not available with a combo box.

I think the only way you'll be able to do this is with code (SetFocus) as in the other example, but that sounds pretty tedious.



BTW, I'm a Captain Morgan drinker, but you can e-mail me some of that. :D
 

Winkypop

Access Tard
Local time
Tomorrow, 00:57
Joined
Apr 13, 2005
Messages
8
Thanks guys

I only have 5 questions, I said it was a basic form. So I will experiment with the SetFocus code.

Cptn Morgan eh? Nice.

If you ever get the chance try some Bundaberg Rum

http://www.bundabergrum.com.au/

Cheers guys.
 

Users who are viewing this thread

Top Bottom