Stafford
Registered User.
- Local time
- Today, 15:46
- Joined
- Aug 20, 2002
- Messages
- 23
Don't whether to Post in Forms or VBA, here goes.
I have a Text box that is a key field, it requires 6 Alpha Numerics.
What I would like, is for the User to enter the Key Field in Add Record mode, in The AfterUpdate event (Or any such event that will work)
I would like code to search for a duplicate record. If a match is found I want a "YesNoCancel" option to display "This record already exists, do you want to update it?"
If Yes Go to the record and allow the edit.
If No they can re-enter the Key Field to allow for Typos
If Cancel, well it just cancels I guess
I was working on this code with a friend who knows a little VBA and we got the Message box up, but nothing else. Now the message box doesn't even pop up.
Is this all wrong?
Private Sub txtApo_AfterUpdate()
' Find the Record that matches the control.
Dim rs As Object
Dim varBkmrk As Variant
Set rs = Me.RecordsetClone
varBkmrk = rs.Bookmark
rs.FindFirst "[APO/Sabre File Number]" = "" & Me![txtApo] & ""
If Not rs.NoMatch Then
Dim msg, style, varchoice
msg = "This record already exists. Do you want to update it?"
style = vbYesNoCancel
varchoice = MsgBox(msg, style)
If varchoice = vbYes Then
dummy = "Yes"
Else
dummy = "No"
End If
rs.Bookmark = varBkmrk
End If
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
Stafford Harriman
I have a Text box that is a key field, it requires 6 Alpha Numerics.
What I would like, is for the User to enter the Key Field in Add Record mode, in The AfterUpdate event (Or any such event that will work)
I would like code to search for a duplicate record. If a match is found I want a "YesNoCancel" option to display "This record already exists, do you want to update it?"
If Yes Go to the record and allow the edit.
If No they can re-enter the Key Field to allow for Typos
If Cancel, well it just cancels I guess
I was working on this code with a friend who knows a little VBA and we got the Message box up, but nothing else. Now the message box doesn't even pop up.
Is this all wrong?
Private Sub txtApo_AfterUpdate()
' Find the Record that matches the control.
Dim rs As Object
Dim varBkmrk As Variant
Set rs = Me.RecordsetClone
varBkmrk = rs.Bookmark
rs.FindFirst "[APO/Sabre File Number]" = "" & Me![txtApo] & ""
If Not rs.NoMatch Then
Dim msg, style, varchoice
msg = "This record already exists. Do you want to update it?"
style = vbYesNoCancel
varchoice = MsgBox(msg, style)
If varchoice = vbYes Then
dummy = "Yes"
Else
dummy = "No"
End If
rs.Bookmark = varBkmrk
End If
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
Stafford Harriman