A
Applebaum
Hello,
I have a combo box with a Not-in-list code which inserts what the user typed
into a table. It works fine, but I'd like to expand this insert to add
specific text to another field. The combo list is for Vendors. When a new
Vendor name is typed in, the user is prompted to add it, and the code
inserts the text into tblVendors.CompanyName. There's another field in
tblVendors called PersonOrOrganization, I'd like to add the word
"Organization" to that field along with the insert into CompanyName. I
cannot figure out the right protocol to use. Here's what I have so far, if
anyone could help out I'd be most grateful!!
Private Sub Combo0_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_Combo0_NotInList
Dim ctl As Control
Dim strSQL As String
' Return Control object that points to combo box.
Set ctl = Me!Combo0
' Prompt user to verify they wish to add new value.
If MsgBox("Item entered is not in list. Add it?", vbOKCancel) = vbOK
Then
' Set Response argument to indicate that data is being added.
Response = acDataErrAdded
' Add string in NewData argument to products table.
strSQL = " INSERT INTO tblVendors (CompanyName) SELECT '" & NewData
& "'"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
ctl.Value = NewData
DoCmd.SetWarnings True
Else
' If user chooses Cancel, suppress error message and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
Exit_Combo0_NotInList:
Exit Sub
Err_Combo0_NotInList:
'errorstuff
End Sub
I came up with a workaround to this, which brings up its own problem. The
AfterUpdate of this combo box takes the user to another form; I had put a
line in which set the field PersonOrOrganization to "Organization". This
worked perfectly, except I have other code in that form which gets triggered
when the form IsDirty, and adding "Organization" made the form dirty. If
someone made no changes, when closing the form they were prompted (as per my
code) whether or not to save changes.
Again, thanks for any input!!
Cheers,
Matthew
I have a combo box with a Not-in-list code which inserts what the user typed
into a table. It works fine, but I'd like to expand this insert to add
specific text to another field. The combo list is for Vendors. When a new
Vendor name is typed in, the user is prompted to add it, and the code
inserts the text into tblVendors.CompanyName. There's another field in
tblVendors called PersonOrOrganization, I'd like to add the word
"Organization" to that field along with the insert into CompanyName. I
cannot figure out the right protocol to use. Here's what I have so far, if
anyone could help out I'd be most grateful!!
Private Sub Combo0_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_Combo0_NotInList
Dim ctl As Control
Dim strSQL As String
' Return Control object that points to combo box.
Set ctl = Me!Combo0
' Prompt user to verify they wish to add new value.
If MsgBox("Item entered is not in list. Add it?", vbOKCancel) = vbOK
Then
' Set Response argument to indicate that data is being added.
Response = acDataErrAdded
' Add string in NewData argument to products table.
strSQL = " INSERT INTO tblVendors (CompanyName) SELECT '" & NewData
& "'"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
ctl.Value = NewData
DoCmd.SetWarnings True
Else
' If user chooses Cancel, suppress error message and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
Exit_Combo0_NotInList:
Exit Sub
Err_Combo0_NotInList:
'errorstuff
End Sub
I came up with a workaround to this, which brings up its own problem. The
AfterUpdate of this combo box takes the user to another form; I had put a
line in which set the field PersonOrOrganization to "Organization". This
worked perfectly, except I have other code in that form which gets triggered
when the form IsDirty, and adding "Organization" made the form dirty. If
someone made no changes, when closing the form they were prompted (as per my
code) whether or not to save changes.
Again, thanks for any input!!
Cheers,
Matthew