Kryst51
Singin' in the Hou. Rain
- Local time
- Today, 01:35
- Joined
- Jun 29, 2009
- Messages
- 1,898
I have two comboboxes on a form.
One combo-box to find a particular record on the form, and another combobox which looksup values in a different table and places the pk into the fk of the table the form is bound to.
This second combo box contains a list of vendors. My user may need to add another vendor, so I created a not-in-list for that combo-box, and used the same event to then assign that number to the record on the form like it would have done if it was originally in the list.
Now, however, the form requeries and sets back to the first available record. When I need it to still display the record it was on before the not-in-list event.
Here is the code in my second combo-box:
I had a thought that I might be able to set the form back to the desired record, as when the form resets, the ID I need is still in the first combo-box (the lookup one) Although, I don't know how to do this, or if there is a better way to do what I need that doesn't require this fancy footwork, other than a "new" pop-up form for a new vendor. (Although If I have to, I will do that. )
One combo-box to find a particular record on the form, and another combobox which looksup values in a different table and places the pk into the fk of the table the form is bound to.
This second combo box contains a list of vendors. My user may need to add another vendor, so I created a not-in-list for that combo-box, and used the same event to then assign that number to the record on the form like it would have done if it was originally in the list.
Now, however, the form requeries and sets back to the first available record. When I need it to still display the record it was on before the not-in-list event.
Here is the code in my second combo-box:
Code:
Private Sub cmbVendorName_NotInList(NewData As String, Response As Integer)
On Error GoTo cmbVendorName_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 = "Vendor Name: '" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
i = MsgBox(Msg, vbQuestion + vbYesNo, "This vendor is not in the list...")
If i = vbYes Then
strSQL = "INSERT INTO tblVendors([VendorName])" & _
" SELECT """ & NewData & """ AS VendorName;"
'Debug.Print strSQL
Response = acDataErrContinue
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Response = acDataErrAdded
DoCmd.SetWarnings True
Else
Response = acDataErrContinue
End If
cmbVendorName_NotInList_Exit:
Exit Sub
cmbVendorName_NotInList_Err:
MsgBox Err.Number & ", " & Err.Description, vbCritical, "Error"
Resume cmbVendorName_NotInList_Exit
End Sub
I had a thought that I might be able to set the form back to the desired record, as when the form resets, the ID I need is still in the first combo-box (the lookup one) Although, I don't know how to do this, or if there is a better way to do what I need that doesn't require this fancy footwork, other than a "new" pop-up form for a new vendor. (Although If I have to, I will do that. )