V
venus as a boy
Hello,
I was supplied the following code which I am having trouble with:
Private Sub txtSSN_BeforeUpdate(Cancel as Integer)
Dim strMsg As String
Dim iAns As Integer
Dim rs As DAO.Recordset ' reserve a variable
Set rs = Me.RecordsetClone ' set it to this form's recordsource
rs.FindFirst "[SSN] = '" & Me!txtSSN & "'" ' is this a dup?
If Not rs.NoMatch Then ' yes it is
Cancel = True ' don't enter the SSN in the table
strMsg = "This SSN already exists!" & _
" Click Yes to go to it, Cancel to retry"
iAns = MsgBox(strMsg, vbYesCancel)
If iAns = vbYes Then
Me.Undo ' erase the data on the form
Me.Bookmark = rs.Bookmark ' move to the record
Else
Me.txtSSN.Undo ' just erase the SSN
End If
End If
End Sub
I am getting an error about like "Macro doesn't exist"
concerning:
Private Sub txtSSN_BeforeUpdate(Cancel as Integer)
Dim strMsg As String
Dim iAns As Integer
Dim rs As DAO.Recordset ' reserve a variable
I entered the code into the Before Update field of my SSN properties in form Employee Data Entry, which relates to table Employee Main.
The idea is to enter an SSN into my form, and if it is matches another SSN it will display the matching record (Hopefully in a dialog box?)
This is to prevent duplicates, since SSN's should be unique.
Please remember I'm a Newb.
Jason
I was supplied the following code which I am having trouble with:
Private Sub txtSSN_BeforeUpdate(Cancel as Integer)
Dim strMsg As String
Dim iAns As Integer
Dim rs As DAO.Recordset ' reserve a variable
Set rs = Me.RecordsetClone ' set it to this form's recordsource
rs.FindFirst "[SSN] = '" & Me!txtSSN & "'" ' is this a dup?
If Not rs.NoMatch Then ' yes it is
Cancel = True ' don't enter the SSN in the table
strMsg = "This SSN already exists!" & _
" Click Yes to go to it, Cancel to retry"
iAns = MsgBox(strMsg, vbYesCancel)
If iAns = vbYes Then
Me.Undo ' erase the data on the form
Me.Bookmark = rs.Bookmark ' move to the record
Else
Me.txtSSN.Undo ' just erase the SSN
End If
End If
End Sub
I am getting an error about like "Macro doesn't exist"
concerning:
Private Sub txtSSN_BeforeUpdate(Cancel as Integer)
Dim strMsg As String
Dim iAns As Integer
Dim rs As DAO.Recordset ' reserve a variable
I entered the code into the Before Update field of my SSN properties in form Employee Data Entry, which relates to table Employee Main.
The idea is to enter an SSN into my form, and if it is matches another SSN it will display the matching record (Hopefully in a dialog box?)
This is to prevent duplicates, since SSN's should be unique.
Please remember I'm a Newb.
Jason