We help IT Professionals succeed at work.

Setfocus command in Access

kdeutsch
kdeutsch asked
on
1,433 Views
Last Modified: 2008-01-09
i am trying to use the setfocus command to focus on a specific text box based on what is picked.   What needs to happen in that when a user picks any of the 4 award types from a combobox the setfocus command will move them to the textbox to fill in information.  Following is what they can pick with the text box that needs to setfocus.
Quality step increase setfocus on amount textbox
suggestion setfocus on amount textbox
sustained superior performance award set focus on amount textbox
time off award setfocus on hours textbox

i am guessing that a variable needs to be set for this, here is some code I was trying but with no luck
dim awardtype as combobox
if awardtype = "suggestion" then
amount.setfocus

This is where i get stuck on if its not, or if I am even correct.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Try using a select case statement based on the combo value:

Select Case MyCombo
      Case "Suggestion", "sustained",  "superior":                <---- Change the actual text in the case statements as needed
             amount.SetFocus
       Case "Time Off":
              Hours.setFocus
End Select
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
> i am guessing that a variable needs to be set for this
You dont need to use a variable for this... just the combobox's Name.  If you prefix it with "Me.", Access VBA's intellisense will help you finish typing the name by autocompleting it for you:

Select Case Me.MyComboName '<--- use the ME prefix
      Case "Suggestion", "sustained",  "superior":                '<---- Change the actual text in the case statements as needed
             amount.SetFocus
       Case "Time Off":
              Hours.setFocus
End Select

Author

Commented:
What would I select for the action on this for teh combobox, on click or on mouse down? I put in code and I get a complie error, statement invaild outside type block.  It highlights the "statements as needed" line.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
Use the AfterUpdate event of your combo box.

Also let me see your code, exactly as you have modified it so that I can help you track down the error.

Author

Commented:
Here is the code

Private Sub Type_AfterUpdate()
Select Case Me.Type
    Case "Quality Step Increase", "Suggestion", "Time off award", "Sustained superior Performance":
statements As needed
    Amount.SetFocus
        Case "time off"
    Hours.SetFocus
End Select
End Sub
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013

Commented:
You mistakenly included my "notes" as code :-)

Try this:

Private Sub Type_AfterUpdate()
Select Case Me.Type
    Case "Quality Step Increase", "Suggestion", "Time off award", "Sustained superior Performance":
        Amount.SetFocus
    Case "time off":
        Hours.SetFocus
End Select
End Sub
back to top

Author

Commented:
aaahh ok, its working now to some extent.
the time off award when piccked on still goes to the amount text box instead of the hours text box.  would I just repeat the same code agian starting underneath the case time off line.  thanks for the help
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I hav seen the light, the differnet case statements drive waht the focus button goes of off.  Got to get back into the Vb book.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.