M
Maarkr
I have a form that I want users to select their name, and if the record
already exists, edit it. Form opens in data entry mode. I'm using a before
and after update event:
Before:
Dim strPick As String
strPick = Nz(DLookup("UserName", "UserInfo", "[UserName] =
Form.[UserName]"), 0)
If strPick = 0 Then
Exit Sub
Else
If MsgBox("A record already exists with that name." & vbCrLf _
& "If you need to edit the info, click OK, otherwise click Cancel to
return to entry screen and close the program.", vbOKCancel) = vbCancel Then
Cancel = True 'don't enter it in table
Me.UserName.Undo
Else
'Cancel = True if I leave this, I can't change data entry mode
but it adds a record that I don't want
Exit Sub
End If
End If
After:
Dim strPick As String
strPick = Nz(DLookup("UserName", "UserInfo", "[UserName] =
Form.[UserName]"), 0)
Debug.Print strPick
If strPick = 0 Then
Exit Sub
Else
Form.DataEntry = False
DoCmd.FindRecord strPick
End If
Am I messing it up by trying to use before and after update to do this? I
tried variations with all under before update but that didn't work. Doing it
this way works but adds a record to the table-- if I try to cancel the before
update I can't shift the data entry mode. I hate before update code.
Thx
already exists, edit it. Form opens in data entry mode. I'm using a before
and after update event:
Before:
Dim strPick As String
strPick = Nz(DLookup("UserName", "UserInfo", "[UserName] =
Form.[UserName]"), 0)
If strPick = 0 Then
Exit Sub
Else
If MsgBox("A record already exists with that name." & vbCrLf _
& "If you need to edit the info, click OK, otherwise click Cancel to
return to entry screen and close the program.", vbOKCancel) = vbCancel Then
Cancel = True 'don't enter it in table
Me.UserName.Undo
Else
'Cancel = True if I leave this, I can't change data entry mode
but it adds a record that I don't want
Exit Sub
End If
End If
After:
Dim strPick As String
strPick = Nz(DLookup("UserName", "UserInfo", "[UserName] =
Form.[UserName]"), 0)
Debug.Print strPick
If strPick = 0 Then
Exit Sub
Else
Form.DataEntry = False
DoCmd.FindRecord strPick
End If
Am I messing it up by trying to use before and after update to do this? I
tried variations with all under before update but that didn't work. Doing it
this way works but adds a record to the table-- if I try to cancel the before
update I can't shift the data entry mode. I hate before update code.
Thx