R
robkiolbasa
I am trying to set the focus of a form when some enters a duplicate
value. The logic is correct, but the focus goes to the next field.
All I want to do is blank the field and toggle back to that same
field. The form is a datasheet view of another table. I would like
duplicates to be allowed, but the end user is prevented from entering
them. I am lost as to why this isn't working. Code below:
Function checkTag() As Integer
Dim db12 As Database
Set db12 = CurrentDb
Dim rs12 As Recordset
Set rs12 = db12.OpenRecordset(Me.Name, dbOpenDynaset)
rs12.MoveFirst
rs12.FindFirst "[ServiceTag] = " & Chr(34) & ServiceTag & Chr(34)
If rs12.NoMatch() Then
checkTag = 1
Else
checkTag = 0
End If
Set rs12 = Nothing
End Function
Private Sub ServiceTag_AfterUpdate()
Call checkTag
If checkTag = 0 Then
MsgBox "The Service Tag is already in use."
ServiceTag.Value = ""
ServiceTag.SetFocus
End If
End Sub
value. The logic is correct, but the focus goes to the next field.
All I want to do is blank the field and toggle back to that same
field. The form is a datasheet view of another table. I would like
duplicates to be allowed, but the end user is prevented from entering
them. I am lost as to why this isn't working. Code below:
Function checkTag() As Integer
Dim db12 As Database
Set db12 = CurrentDb
Dim rs12 As Recordset
Set rs12 = db12.OpenRecordset(Me.Name, dbOpenDynaset)
rs12.MoveFirst
rs12.FindFirst "[ServiceTag] = " & Chr(34) & ServiceTag & Chr(34)
If rs12.NoMatch() Then
checkTag = 1
Else
checkTag = 0
End If
Set rs12 = Nothing
End Function
Private Sub ServiceTag_AfterUpdate()
Call checkTag
If checkTag = 0 Then
MsgBox "The Service Tag is already in use."
ServiceTag.Value = ""
ServiceTag.SetFocus
End If
End Sub