Ok. I am no longer getting a syntax error. Thanks for that.
The two listboxes are still not doing what I need them to do. I want to be
able to click the Category listbox and filter out the category I have for
that particular phone number. The two listboxes are side by side on the same
form.
PC ID is an autonumber ID field of my Phone Category table.
Phone numbers is the name of the table with the phone numbers
Phone Category is the name of the phone categories, such as 'family,
friends, associates etc.'
ListNumbers is the name of the Listbox listing all the phone numbers and
names.
List Category is the name of the Listbox listing just the categories.
I have both tables joined by the PC ID field.
I have the following code in the AfterUpdate of the ListNumbers Listbox:
Private Sub ListNumbers_AfterUpdate()
Me!cbo_ListNumbers.RowSource = "SELECT [PC ID] FROM [Phone numbers] WHERE
[PC ID]= " & Me![cbo_ListCategory]
End Sub
This is the Row Source for the ListCategory Listbox
SELECT [Phone Category].[PC ID], [Phone Category].[Category] FROM [Phone
Category] WHERE [PC ID];
This is the Row Source for the ListNumbers listbox
SELECT [Phone numbers].[Phone numbers ID], [Phone numbers].[First name],
[Phone numbers].[Last name], [Phone numbers].[Home number], [Phone
numbers].[2nd number] FROM [Phone numbers];
There is a combo box to select on the form where I edit the phone numbers.
The combo box has options for the PC ID 'Category such as Family, Friends,
etc'. These categories are saving to the Phone number table for each phone
number.
John W. Vinson said:
Ok, I have set up the Category Table with PC ID as the primary key.
Also as a side note. I have created a relationship between both tables
linking the PC ID fields.
The List box name for the Category is ListCategory
The List box name for the Phone Numbers is ListNumbers
Private Sub ListCategory_AfterUpdate()
Me!cbo_ListNumbers.RowSource = "SELECT Home number FROM "
Phone numbers WHERE PC ID= " & Me!cbo_Phone Category
End Sub
I am getting a Syntax error on the WHERE
As Rob said, you need brackets - blanks are meaningful, and should not be in
fieldnames; in addition, if [PC ID] is a Text field rather than a Number you
need quotemarks around the criterion:
Me!cbo_ListNumbers.RowSource = "SELECT [Home number] FROM " _
& "[Phone numbers] WHERE [PC ID]= '" _
& Me!cbo_Phone Category & "'"
This will set the rowsource to a string like
SELECT [Home number] FROM [Phone numbers] WHERE [PC ID] = 'Cell'
If the ID is a number field ignore this suggestion (until you need to use a
text field in some other context).