Private Sub Contact_Person_NotInList(NewData As String, Response As Integer)
On Error GoTo Contact_Person_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("You are adding " & Chr(34) & NewData & _
Chr(34) & " as a new contact for this customer." & vbCrLf & _
"Are you sure you want do this?" _
, vbQuestion + vbYesNo, "Customer Contacts")
If intAnswer = vbYes Then
strSQL = "INSERT INTO [Customer Contacts Table]([CC_Contact Person],
" & _
"[CC_Company] )" & _
"VALUES ('" & NewData & "', " & _
"Forms![Job Work Orders Form]!Customer);"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Me.Contact_Person.Requery
DoCmd.SetWarnings True
Response = acDataErrAdded
Else
MsgBox "Please select an existing contact from the list then." _
, vbInformation, "Customer Contacts"
Response = acDataErrContinue
End If
Contact_Person_NotInList_Exit:
Exit Sub
Contact_Person_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume Contact_Person_NotInList_Exit
End Sub
Brian Bastl said:
which event are you using to issue the requery???
Christian > said:
DUDE!
I entered the following line in my code and it WORKS!:
Me.Contact_Person.Requery
Except, I get that anoying message "You must save the current field before
you run the Requery action."
Can I enter code to make it save the field before the requery?
:
Christian >,
have you set the response to acDataErrAdded? Then in the AfterUpdate event
of the first combobox, you'll need to issue a requery of the second
combobox.
HTH,
Brian
Thanks guys, I got it to work--sort of using the following code:
strSQL = "INSERT INTO [Customer Contacts Table]([CC_Contact
Person], "
& _
"[CC_Company] )" & _
"VALUES ('" & NewData & "', " & _
"Forms![Job Work Orders Form]!Customer);"
Here's the problem. This particular combo box is sync'd with
another
by
using a SQL statement as the row source.
SELECT [Customer Contacts Table].CC_CustomerContactID, [Customer Contacts
Table].[CC_Contact Person], [Customer Contacts Table].CC_Company FROM
[Customer Contacts Table] WHERE ((([Customer Contacts
Table].CC_Company)=Forms![Job Work Orders Form]!Customer)) ORDER BY
[Customer
Contacts Table].[CC_Contact Person];
So now, with my not in list code, it adds the contact to the contacts
table,
but I get an error after and it still doesn't have it in the combo
box
for
this field--not until i open a new form...
So I learned somehting from both of you, but I learned the wrong thing.
I'm
not even sure what to ask at this point. :|
:
Christian,
using what you have provided:
strSQL = "INSERT INTO [Customer Contacts Table] ([CC_Contact Person], "
& _
"[CC_Company]) VALUES ('" & NewData & "', " & _
"'" & Forms![Job Work Orders Form]!Customer & "')"
CurrentDb.Execute strSQL, dbFailOnError
HTH,
Brian
I have a NotInList Event Code. In that code I have an strSQL
and
I
want
it
to do two things, not just one.
Here are both of what I want to happen:
strSQL = "INSERT INTO [Customer Contacts Table]([CC_Contact Person]) "
& _
"VALUES ('" & NewData & "');"
strSQL = "INSERT INTO [Customer Contacts Table]([CC_Company])
" &
_
"VALUES (Forms![Job Work Orders Form]!Customer);"
How do I combine the above code correctly?