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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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,190,795
Messages
5,982,963
Members
439,808
Latest member
agutosay

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
Top