No In List Event

I

iholder

I am having trouble adding a record to the list. The list source is a is
query called "qryCountries" on a ComboBox control. The coding is:

Private Sub Country_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
' Return Control object that points to combo box.
Set ctl = Me!Country
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", _
vbYesNo) = vbYes Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source.
ctl.RowSource = ctl.RowSource & ";" & NewData
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If

End Sub

I am getting an error message as follows:
"The record source "qryCountries.Africa" specified a this form does no
exist.
Note: The ComboBox is bound to a field called Country is another table
called "tblParkingSpaces."

Africa is the country being added to the list.

Help defining the cause of the problem.

Thank You
Ileana
 
G

ghetto_banjo

first off, Africa is not a country. ;-)


ok now to the Access stuff:

this isn't the correct way to add rows to the list.

This line of code here:
ctl.RowSource = ctl.RowSource & ";" & NewData

is making the Row Source of the list box equal:
qryCountries;Africa

This will not work. The list box is expecting just a query/table name
here. You cannot just append country names to this Row Source
property.


You should try appending the country name to whatever table
qryCountries is selecting from, and then just Requery your listbox.
Or (not recommended) you can make the Row Source Type into a Value
List, and then you could use your above code to add new entries.
 
D

De Jager

iholder said:
I am having trouble adding a record to the list. The list source is a is
query called "qryCountries" on a ComboBox control. The coding is:

Private Sub Country_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
' Return Control object that points to combo box.
Set ctl = Me!Country
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", _
vbYesNo) = vbYes Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source.
ctl.RowSource = ctl.RowSource & ";" & NewData
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If

End Sub

I am getting an error message as follows:
"The record source "qryCountries.Africa" specified a this form does no
exist.
Note: The ComboBox is bound to a field called Country is another table
called "tblParkingSpaces."

Africa is the country being added to the list.

Help defining the cause of the problem.

Thank You
Ileana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top