TheDrescher said:
It seems I'm trading error for error. Utilizing the code you gave me it
comes back saying the value I entered in 'Category' is invalid for the field.
I was using SELECT since there are 15 categories and 128
category/subcategory combinations. If this is an inefficient way to code it,
how would I list the field specifically?
"the value I entered in 'Category' is invalid for the field"
does not sound like a a query error message. Maybe "it"
does not refer to the query.
If the message was from the query and said somthing about a
data type mismatch, then see Dirk's reply. As Dirk said,
the data type (number, text, etc) is essential to getting
the query to work,
If the message appeared when you tried to select an item in
the list, please provide more details.
The 'Category' field pulls from the 'Categories' table with two columns,
"ID" and "Category" so:
ColumnCount = 2
ColumnWidths = 0";1"
Bound Column = 1(gives response above), 2 (returns VBA code in Category box
and returns "Syntax error in WHERE clause")
Now you are losing me. It doesn't make sense to play around
with the BoundColumn property. It needs to be exactly what
your program requires it to be. Most likely it should be
the number that corresponds to the ID field in the query's
field list. If BoundColumn is 1, then I would expect the
query to be:
"SELECT ID, Category FROM . . .
:
That's what I thought. Try it this way:
Me.SubCatBox.RowSource = "SELECT * FROM SubCats WHERE
Category = """ & Nz(Me.Category, "") & """"
It is not good to use SELECT *, especially in a combo/list
box row source. Instead, list the specific fields needed
for the control's list. Don't forget that the control's
BoundColumn, ColumnWidths and ColumnCount properties must
agree with the listed fields.
TheDrescher wrote:
Me.SubCatBox.RowSource = "SELECT * FROM tbl[SubCats] " & "WHERE
Fld[Category]" = """ & Nz(Me.Category, "") & """""
:
It sounds like the = sign got out of the quotes. What does
the code look like after the changes to fix the names?
TheDrescher wrote:
Thanks for the heads up. After utlizing the example you provided, when I go
to choose the sub-category it states that the Record Source 'False' does not
exist. is there some additional parameter I need to specify?
:
TheDrescher wrote:
I'm coding a portion of the form that populates a set of options in one
field (SubCatBox) based on the value selected in another (Categories). I've
created the required tables (named Categories and SubCats) and have set the
'After Update' event procedure for the Categories field to equal:
Private Sub Categories_AfterUpdate()
Me.SubCatBox.RowSource = "SELECT * FROM tbl SubCats " & "WHERE Fld Category
= """ & Nz(Me.Category, "") & """"
End Sub
I keep getting a 'Syntax Error (missing operator) in query expression
'FldCategory = "1"' . How would I correct this? Thanks!
any time you use a name that contains a space or other
funky characters, you MUST enclose the name in [ ]
....="SELECT * FROM [tbl SubCats] " & "WHERE [Fld Category]
= """ & Nz(Me.Category, "") & """"
In general, you should not use names that require the [ ]
Something like tblSubCats and fldCategory are just as
menaingful and avoid the problem you posted.