G
Guest
I have a main form that is unbound with an unbound combo box. The users
would like to be able to add a New CTAName to the list in the combo box. I
have tried to use the NotInList event, but something is not working.
Here is what is happening when testing:
1. After typing in a new CTA Name "Alpha Omega" it comes up with a message
"Do you want to ADD this to the Database? yes or no. I click yes and it
gives this:
2. "This item is not listed in the dropdown box" then it
3. Brings up the dropdown box waiting for the user to choose a name already
listed. NOT what I want. I want to be able to add the new CTA NAme of
Alpha Omega and all of it's info along with it.
Here is my code:
Private Sub CTAName_Combo_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[CTAName] = '" & Me![CTAName_Combo] & "'"
If rs.NoMatch = True Then
MsgBox "Selected CTA Name not found!"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End Sub
Private Sub CTAName_Combo_NotInList(NewData As String, Response As Integer)
Dim db As Database
Dim rs As Recordset
If MsgBox(NewData & " is not in the list. Would you like to add it to
the database?", vbQuestion + vbYesNo, "Add new CTA Name?") = vbNo Then
DoCmd.OpenForm "frmMyPopup", , , , acDialog, NewData
Response = acDataErrAdded
Else
DoCmd.RunCommand acCmdRecordsGoToNew
On Error Resume Next
' add initial data
With Me.RecordsetClone
.Fields("CTAName") = NewData
.Fields("IDNumber") = Now
.Fields("CTAAddress") = Now
.Fields("CTACity") = Now
.Fields("CTAState") = Now
.Fields("CTAZip") = Now
.Fields("CTAPhone") = Now
.Fields("CTAFax") = Now
.Fields("CTAEmail") = Now
.Fields("CTAContactName1") = Now
.Fields("CTAContactPhone1") = Now
.Fields("CTAContactFax1") = Now
.Fields("CTAContactEmail") = Now
End With
' save data to table
Me.Dirty = False
' requery the combo box to include new server in dropdown list
Me.CTAName_Combo.Undo
Response = acDataErrContinue
Response = acDataErrAdded
End If
End Sub
I would appreciate any help.
Thanks
would like to be able to add a New CTAName to the list in the combo box. I
have tried to use the NotInList event, but something is not working.
Here is what is happening when testing:
1. After typing in a new CTA Name "Alpha Omega" it comes up with a message
"Do you want to ADD this to the Database? yes or no. I click yes and it
gives this:
2. "This item is not listed in the dropdown box" then it
3. Brings up the dropdown box waiting for the user to choose a name already
listed. NOT what I want. I want to be able to add the new CTA NAme of
Alpha Omega and all of it's info along with it.
Here is my code:
Private Sub CTAName_Combo_AfterUpdate()
Dim rs As Object
Set rs = Me.RecordsetClone
rs.FindFirst "[CTAName] = '" & Me![CTAName_Combo] & "'"
If rs.NoMatch = True Then
MsgBox "Selected CTA Name not found!"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing
End Sub
Private Sub CTAName_Combo_NotInList(NewData As String, Response As Integer)
Dim db As Database
Dim rs As Recordset
If MsgBox(NewData & " is not in the list. Would you like to add it to
the database?", vbQuestion + vbYesNo, "Add new CTA Name?") = vbNo Then
DoCmd.OpenForm "frmMyPopup", , , , acDialog, NewData
Response = acDataErrAdded
Else
DoCmd.RunCommand acCmdRecordsGoToNew
On Error Resume Next
' add initial data
With Me.RecordsetClone
.Fields("CTAName") = NewData
.Fields("IDNumber") = Now
.Fields("CTAAddress") = Now
.Fields("CTACity") = Now
.Fields("CTAState") = Now
.Fields("CTAZip") = Now
.Fields("CTAPhone") = Now
.Fields("CTAFax") = Now
.Fields("CTAEmail") = Now
.Fields("CTAContactName1") = Now
.Fields("CTAContactPhone1") = Now
.Fields("CTAContactFax1") = Now
.Fields("CTAContactEmail") = Now
End With
' save data to table
Me.Dirty = False
' requery the combo box to include new server in dropdown list
Me.CTAName_Combo.Undo
Response = acDataErrContinue
Response = acDataErrAdded
End If
End Sub
I would appreciate any help.
Thanks