Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Before Update problem 1

Status
Not open for further replies.

mommom

Technical User
Nov 14, 2003
208
US
Right now if I type in a SSN for example:111-11-1111 and it says it already exists. Instead of opening that SSN it opens the first record. Is there something else I need to add to the code listed below?


Private Sub SSN_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("[SSN]", "Security", "[SSN]= '" & Me![SSN] & "'")) Then
MsgBox "This SSN already exists."
Cancel = True
Me.Undo
DoCmd.GoToRecord , , acFirst
DoCmd.FindRecord SSN

End If

End Sub
 
Can someone please help me with this. I just don't know why it keeps going to the first record instead of opening the record with the SSN that was put in.
 
Try DoCmd.FindRecord "[SSN]= '" & Me![SSN] & "'"

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
mommom . . .

The question is . . . what do you want to do if the SSN exist?

Calvin.gif
See Ya! . . . . . .
 
Hello AceMan,

If the SSN exist I want the record to open up.
 
missinglinq,

I tried as listed below and it still doesn't work.


Private Sub SSN_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("[SSN]", "Security", "[SSN]= '" & Me![SSN] & "'")) Then
MsgBox "This SSN already exists."
Cancel = True
Me.Undo
DoCmd.GoToRecord , , acFirst
DoCmd.FindRecord "[SSN]= '" & Me![SSN] & "'"
End If

End Sub


 
And what about this ?
Code:
Private Sub SSN_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("SSN", "Security", "SSN='" & Me![SSN] & "'")) Then
    MsgBox "This SSN already exists."
    Cancel = True
    Me.Undo
    Me.Recordset.FindFirst "SSN='" & Me![SSN] & "'"     
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello PHV,

When I put the code in after it says "This SSN already exists."

The field goes blank and doesn't bring up the information.

 
doesn't

me.undo

remove the value you want to search for?

you need to capture that to a variable and then search for the variable

Private Sub SSN_BeforeUpdate(Cancel As Integer)

Dim strSSN As String

If Not IsNull(DLookup("[SSN]", "Security", "[SSN]= '" & Me![SSN] & "'")) Then
MsgBox "This SSN already exists."
strSSN = Me![SSN]
Cancel = True
Me.Undo
DoCmd.GoToRecord , , acFirst
DoCmd.FindRecord "[SSN]= '" & strSSN & "'"
End If

End Sub


PaulF
 
[CODE Revised]
Private Sub SSN_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("SSN", "Security", "SSN='" & Me![SSN] & "'")) Then
MsgBox "This SSN already exists."
Cancel = True
Me.Recordset.FindFirst "SSN='" & Me![SSN] & "'"
End If[/CODE]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello PHV,

Did your code and it gave me a Run-time error '3426': This action was cancelled by an associated object.


Hello Paul,

Tried your code also and it brought me to the first record as my code is doing now.

 
mommom
I like to use RecordsetClone for this type of action

Private Sub SSN_BeforeUpdate(Cancel As Integer)

Dim strSSN As String

If Not IsNull(DLookup("[SSN]", "Security", "[SSN]= '" & Me![SSN] & "'")) Then
MsgBox "This SSN already exists."
strSSN = Me![SSN]
Cancel = True
Me.Undo

With Me.RecordSetClone
.FindFirst "SSN = '" & strSSN & "'"
If Not .NoMatch Then
Me.Bookmark = Me.RecordSetClone.Bookmark
End If
End With
End If
End Sub

PaulF
 
Thank you Paul that works.

Thank you so much for helping me with this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top