-
VBA Code setfocus
I have a button on my form that adds a new record but I want it to focus a specific field on the form becasue the focus stays on the button. How do I do this.
ROb
-
-
-
set focus
Access has a bug in it that causes the set focus command to misbehave on occasion.
A workaround is for you to set the focus on the control immediately prior to (i.e., immediately prior in the tab order) the one you really want focus on and then set the focus on the control you really want it on.
Thus, in the snippet below, I want the focus on the form to go to OrderNumber, but I set it on Refinance first and then re-set it to OrderNumber.
Clunky, yes, but it works.
Code:
'...this is just a snippet...
Me!Refinance.SetFocus
Me!OrderNumber.SetFocus
'An Access bug makes you set the focus to the prior control on a form
'before you can re-set the focus to the control you want it on
'...end of snippet...
-
On your button add the following code:
MyField.SetFocus
The button will now add a new record and set focus to your field.
-
I came up with this solution:
Code:
'--------------------------------------------
'This procedure forces the user to enter an
'order number as well as allowing the user to
'choose the option of going to the last order
'entered
'--------------------------------------------
Private Sub OrderNumber_LostFocus()
If IsNull(Me!OrderNumber) Then
If (MsgBox("Enter an order number in the format 03-1234." _
& vbCrLf & "Click CANCEL to return to the last order entered.", _
vbOKCancel, "You must enter an order number first!") _
= vbOK) Then
'--------------------------------------------
'An Access bug makes you set the focus to the
'prior or next control on a form before you
'can re-set the focus to the control you want
'it on
'--------------------------------------------
Me!Refinance.SetFocus
Me!OrderNumber.SetFocus
Else
DoCmd.GoToRecord , , acLast
End If
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|