Set Focus question

Dartagnan

Active Member
Joined
Jun 19, 2002
Messages
386
I am using Access 2002 SP3 and I have the following code running behind the StaffID field in the After Update event.

If Me.StaffID = DLookup("[staffid]", "[staff]", "[staffid] = form![staffid]") Then
MsgBox ("The Staff ID you entered is already in use." & vbCrLf & "Please enter a new Staff ID."), vbExclamation
Me.StaffID.SetFocus
End If

For some reason the setfocus doesn't work. My prompt keeps moving to the next field down. I want to make sure they can't leave the field until they entere a valid staff id or they click the Cancel button. On the other hand I don't want the message to fire multiple times either. If I put the same code in the On Exit event the message box fires twice.

Any thoughts?

Thank you in advance.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I've one idea - use a combobox to list the existing staff IDs.

You could also use it's NotInList event if you want to create new staff IDs and add them to the table,
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top