?
Solved

Setfocus command in Access

Posted on 2007-10-01
9
Medium Priority
?
1,371 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.
0
Comment
Question by:kdeutsch
  • 5
  • 4
9 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 19995873
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
0
 
LVL 61

Expert Comment

by:mbizup
ID: 19995932
> 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
0
 

Author Comment

by:kdeutsch
ID: 19997903
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.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 61

Expert Comment

by:mbizup
ID: 19997955
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.
0
 

Author Comment

by:kdeutsch
ID: 19998051
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
0
 
LVL 61

Expert Comment

by:mbizup
ID: 19998085
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
0
 

Author Comment

by:kdeutsch
ID: 19998128
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
0
 
LVL 61

Accepted Solution

by:
mbizup earned 800 total points
ID: 19998399
Basically, each case (and you can have as many as needed) will run different code.  As you have it written, you saying this:

If the type combobox selection is "Quality Step Increase", "Suggestion", "Time off award", or  "Sustained superior Performance", set the focus on Amount.

If the type combobox selection is "Time off", set the focus on Hours.

Are "Time Off" and  "Time off award" different selections?  The code is currently treating them as 2 different selections.

Try this:


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

0
 

Author Comment

by:kdeutsch
ID: 19998486
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.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

850 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