C
Chris
I am using the following code (found here) to add a record to my table. It
adds the record. Of course, I need to do some entry work so I will need to
pull up that form making it editable, etc.
My problem is any code I add after the "ADDS NEW CLIENT RECORD" below
returns the error 3022, duplicate values (this is the key field). If I take
out the added code the record is added, but remains just the keyfield.
I would like, after adding the record, to return to that record on my form.
I can go on from there to complete the form. Can someone please instruct me
how to do so?
Private Sub cboClient_NotInList(NewData As String, Response As Integer)
'ADDS NEW CLIENT RECORD
If MsgBox("Name is not in list. Add it?", vbOKCancel) = vbOK Then
Dim strSQL As String
strSQL = " INSERT INTO [tbl 1 Client]([ClientID]) SELECT
""" & NewData & """;"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
' If user chooses Cancel, suppress error message
Response = acDataErrContinue
End If
'GETS NEW CLIENT INTO COMBO BOX
Me.Dirty = False
Me.cboClient.Requery
'GOES TO NEW RECORD
On Error Resume Next
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ClientID] = '" & Me![cboClient] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
adds the record. Of course, I need to do some entry work so I will need to
pull up that form making it editable, etc.
My problem is any code I add after the "ADDS NEW CLIENT RECORD" below
returns the error 3022, duplicate values (this is the key field). If I take
out the added code the record is added, but remains just the keyfield.
I would like, after adding the record, to return to that record on my form.
I can go on from there to complete the form. Can someone please instruct me
how to do so?
Private Sub cboClient_NotInList(NewData As String, Response As Integer)
'ADDS NEW CLIENT RECORD
If MsgBox("Name is not in list. Add it?", vbOKCancel) = vbOK Then
Dim strSQL As String
strSQL = " INSERT INTO [tbl 1 Client]([ClientID]) SELECT
""" & NewData & """;"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
' If user chooses Cancel, suppress error message
Response = acDataErrContinue
End If
'GETS NEW CLIENT INTO COMBO BOX
Me.Dirty = False
Me.cboClient.Requery
'GOES TO NEW RECORD
On Error Resume Next
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[ClientID] = '" & Me![cboClient] & "'"
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub