Hi, hoping someone can help me with the following piece of Access code.
The coAddNew command button unlocks the field AssetID and moves focus to the AssetID field. On update of the AssetID field code checks for existing record. If found focus should be set back to the AssetID field for re-entry.
Problem is focus always goes to the field after the AssetID on.
Can anyone explain what I am doing wrong, I thought Me.AssetID.SetFocus should force the cursor to go to that field, as it does in the AddNew bit of code, NOT the field after it.
Many thanks
Colin
Private Sub AssetID_AfterUpdate()
If Not IsNull(AssetID) Then
If DCount("AssetID", "tbEqld", "[AssetID] = '" & AssetID & "'") > 0 Then
MyMsg = MsgBox("Equipment ID Exists, Please Enter New ID or Click Cancel to Exit!", vbOKCancel, "Add New Equipment")
If MyMsg = 1 Then
Me.AssetID.SetFocus 'This SetFocus moves the cusor to the field after Me.AssetID
Else
Me.Undo
DoCmd.GoToRecord , , acFirst
Exit Sub
End If
End If
End If
'Me.AssetID.Locked = True
End Sub
__________________________________________________ ___________
Private Sub coAddNew_Click()
On Error GoTo Err_coAddNew_Click
Me.AssetID.Locked = False
'strSaveOption = "N"
MyMsg = MsgBox("Enter New Equipment ID and Data or Cancel to Exit!", vbOKCancel, "Add New Equipment")
If MyMsg = 1 Then
DoCmd.GoToRecord , , acNewRec
Me.AssetID.SetFocus ' This SetFocus works as it should and moves cursor to Me.AssetID
Else
Exit Sub
End If
Exit_coAddNew_Click:
Exit Sub
Err_coAddNew_Click:
MsgBox Err.Description
Resume Exit_coAddNew_Click
End Sub