Hi MattDylan,
For starters, your code should look like this:
Private Sub Form_Current()
If Me.NewRecord Then Me.PickerID = Me.txEmployeeBadgeID
End Sub
hnasr's comment above was intended to mean replace "End If" with "End Sub"
i.e.
End IF --> End Sub
Unfortunately, I'm going to give you a politician's answer:
Access provides a built in function to move the cursor directly to any control on a form. This is the SetFocus function explained above.
eg.
LabelBox.SetFocus
However, it is not that simple.
What the experts have been trying to explain above, is that every scanned label needs its own record. Every time you move to a new record, all the fields will be blank, including the Employee ID badge field.
If you don't want the employee to have to scan their badge for each record, you need to store the badge number somewhere else and reenter it automatically with every new record.
That is where the On Current event comes into it. The Current event is triggered every time the form moves to a different record.
So, what do you need to do...?
Back-up your form (copy and paste) then replace all code with code below:
I have blatantly copied most of it from expert posts above.
(Note, you may need to change some names to match your field names. Hope it works as untested. Let me know ho it goes.)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
|
'Store the pickerid/badge number between records
Private BADGE_NUMBER As String
'Check valid badge number entered before adding scanned labels
Public Sub Cheat_Label_BeforeUpdate(Cancel As Integer)
If Nz(BADGE_NUMBER, "") = "" Then
Cancel = True
MsgBox "You have not scanned your Employee Badge.", vbOKOnly
Me.PickerID.SetFocus
End If
End Sub
'Go to new record after scanning each label
Public Sub Cheat_Label_AfterUpdate()
DoCmd.RunCommand acCmdRecordsGoToNew
End Sub
'When changing records, check badge number has been scanned then enter badge number
'into PickerID field.
Public Sub Form_Current()
If Me.NewRecord Then
If BADGE_NUMBER = "" Then
PickerID.SetFocus
Else
PickerID = BADGE_NUMBER
End If
End If
End Sub
'After PickerID has been entered, store the badge number for later records.
Public Sub PickerID_AfterUpdate()
BADGE_NUMBER = PickerID
End Sub
|