Kryst51
Singin' in the Hou. Rain
- Local time
- Today, 05:54
- Joined
- Jun 29, 2009
- Messages
- 1,896
Item added during "not in list", combo box display, form does not jump to record
I have a combo box, this combo box uses the "Not In List" event to add a record to a table if that record is not already entered. The event works great, but after it is over, the combo box displays the new number but doesn't make the form jump to that record, it goes to the first record in the table. I am just beginning to make use of this event, so I don't fully understand how it works, so any help is appreciated. The form is bound to the table.
Here is my combo box After update event code:
Here is the Not in List event code:
I have a combo box, this combo box uses the "Not In List" event to add a record to a table if that record is not already entered. The event works great, but after it is over, the combo box displays the new number but doesn't make the form jump to that record, it goes to the first record in the table. I am just beginning to make use of this event, so I don't fully understand how it works, so any help is appreciated. The form is bound to the table.
Here is my combo box After update event code:
Code:
Private Sub cmbInvoiceLookup_AfterUpdate()
On Error GoTo cmbInvoiceLookup_ErrHandler:
' Find the record that matches the control.
Dim rs As Object
Set rs = Me.Recordset.Clone
rs.FindFirst "[pkInvoiceID] = " & Str(Nz(Me![cmbInvoiceLookup], 0))
Me.InvoiceNumber.Visible = True
Me.SalesOrderNumber.Visible = True
Me.cmbSalesman.Visible = True
Me.cmbCustomerID.Visible = True
Me.cmbCustomerName.Visible = True
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Exit Sub
cmbInvoiceLookup_ErrHandler:
MsgBox Err.Number & ", " & Err.Description
Exit Sub
End Sub
Here is the Not in List event code:
Code:
Private Sub cmbInvoiceLookup_NotInList(NewData As String, Response As Integer)
On Error GoTo cmbInvoiceLookup_NotInList_Err
Dim strSQL As String
Dim i As Integer
Dim Msg As String
'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub
Msg = "Invoice: '" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
i = MsgBox(Msg, vbQuestion + vbYesNo, "Invoice is not in list...")
If i = vbYes Then
strSQL = "INSERT INTO tblInvoices([InvoiceNumber]) " & _
"values (" & NewData & ");"
'Debug.Print strSQL
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Response = acDataErrAdded
DoCmd.SetWarnings True
Else
Response = acDataErrContinue
End If
cmbInvoiceLookup_NotInList_Exit:
Exit Sub
cmbInvoiceLookup_NotInList_Err:
MsgBox Err.Number & ", " & Err.Description, vbCritical, "Error"
Resume cmbInvoiceLookup_NotInList_Exit
End Sub