help with cascading combobox

G

Guest

I have a table named "Inventory06" with columns ID, Item, and Description.
On my form, I have two comboboxes - cboItem and cboDescription - that I am
wanting to have pull the corresponding info from the Item and Description
columns. I have the cboItem combo pulling correctly. However, when I click
on cboDescription, it gives me a "Syntax error in FROM clause" error. Below
is the code I have and where it is. Any help is greatly appreciated.

cboItem combo:
RowSource: SELECT Inventory06.ID,Inventory06.Item FROM Inventory06;

AfterUpdate:
Private Sub cboItem_AfterUpdate()
Dim sDescription As String

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description]" & _
"FROM Inventory06" & _
"WHERE [ID]=" & Me.cboItem.Value

Me.cboDescription.RowSource = sDescription
Me.cboDescription.Requery
End Sub


cboDescription:
RowSource: SELECT Inventory06.ID, Inventory06.Item, Inventory06.Description
FROM Inventory06;
 
G

Guest

There is no space between the last field to the FROM or WHERE, try

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description] " & _
" FROM Inventory06 " & _
" WHERE [ID]=" & Me.cboItem
 
G

Guest

That partially worked. I no longer get the syntax error, but I still don't
get anything in the cboDescription. I have column count 3, bound column 3,
and column widths 0";0";3". Would it work better if I built a query with
just the Item and Description columns and work off that? And thanks again
for your help.
Steve

Ofer Cohen said:
There is no space between the last field to the FROM or WHERE, try

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description] " & _
" FROM Inventory06 " & _
" WHERE [ID]=" & Me.cboItem


--
Good Luck
BS"D


SteveP said:
I have a table named "Inventory06" with columns ID, Item, and Description.
On my form, I have two comboboxes - cboItem and cboDescription - that I am
wanting to have pull the corresponding info from the Item and Description
columns. I have the cboItem combo pulling correctly. However, when I click
on cboDescription, it gives me a "Syntax error in FROM clause" error. Below
is the code I have and where it is. Any help is greatly appreciated.

cboItem combo:
RowSource: SELECT Inventory06.ID,Inventory06.Item FROM Inventory06;

AfterUpdate:
Private Sub cboItem_AfterUpdate()
Dim sDescription As String

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description]" & _
"FROM Inventory06" & _
"WHERE [ID]=" & Me.cboItem.Value

Me.cboDescription.RowSource = sDescription
Me.cboDescription.Requery
End Sub


cboDescription:
RowSource: SELECT Inventory06.ID, Inventory06.Item, Inventory06.Description
FROM Inventory06;
 
G

Guest

1. Make sure that the value returned by cboItem is correct, it might be
bounded to the wrong field

2. If the ID field type is string, then you need to add single quote before
and after the value

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description] " & _
" FROM Inventory06 " & _
" WHERE [ID]='" & Me.cboItem & "'"

3. Is the requery still there?

--
Good Luck
BS"D


SteveP said:
That partially worked. I no longer get the syntax error, but I still don't
get anything in the cboDescription. I have column count 3, bound column 3,
and column widths 0";0";3". Would it work better if I built a query with
just the Item and Description columns and work off that? And thanks again
for your help.
Steve

Ofer Cohen said:
There is no space between the last field to the FROM or WHERE, try

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description] " & _
" FROM Inventory06 " & _
" WHERE [ID]=" & Me.cboItem


--
Good Luck
BS"D


SteveP said:
I have a table named "Inventory06" with columns ID, Item, and Description.
On my form, I have two comboboxes - cboItem and cboDescription - that I am
wanting to have pull the corresponding info from the Item and Description
columns. I have the cboItem combo pulling correctly. However, when I click
on cboDescription, it gives me a "Syntax error in FROM clause" error. Below
is the code I have and where it is. Any help is greatly appreciated.

cboItem combo:
RowSource: SELECT Inventory06.ID,Inventory06.Item FROM Inventory06;

AfterUpdate:
Private Sub cboItem_AfterUpdate()
Dim sDescription As String

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description]" & _
"FROM Inventory06" & _
"WHERE [ID]=" & Me.cboItem.Value

Me.cboDescription.RowSource = sDescription
Me.cboDescription.Requery
End Sub


cboDescription:
RowSource: SELECT Inventory06.ID, Inventory06.Item, Inventory06.Description
FROM Inventory06;
 
G

Guest

I copied and pasted the sDescription as you sent it below and worked through
a minor error (changed WHERE[ID] to WHERE[Item]) but it works great. Thanks
for all of your help. Definately learned some valuable lessons I can use in
some other databases now.
Steve

Ofer Cohen said:
1. Make sure that the value returned by cboItem is correct, it might be
bounded to the wrong field

2. If the ID field type is string, then you need to add single quote before
and after the value

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description] " & _
" FROM Inventory06 " & _
" WHERE [ID]='" & Me.cboItem & "'"

3. Is the requery still there?

--
Good Luck
BS"D


SteveP said:
That partially worked. I no longer get the syntax error, but I still don't
get anything in the cboDescription. I have column count 3, bound column 3,
and column widths 0";0";3". Would it work better if I built a query with
just the Item and Description columns and work off that? And thanks again
for your help.
Steve

Ofer Cohen said:
There is no space between the last field to the FROM or WHERE, try

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description] " & _
" FROM Inventory06 " & _
" WHERE [ID]=" & Me.cboItem


--
Good Luck
BS"D


:

I have a table named "Inventory06" with columns ID, Item, and Description.
On my form, I have two comboboxes - cboItem and cboDescription - that I am
wanting to have pull the corresponding info from the Item and Description
columns. I have the cboItem combo pulling correctly. However, when I click
on cboDescription, it gives me a "Syntax error in FROM clause" error. Below
is the code I have and where it is. Any help is greatly appreciated.

cboItem combo:
RowSource: SELECT Inventory06.ID,Inventory06.Item FROM Inventory06;

AfterUpdate:
Private Sub cboItem_AfterUpdate()
Dim sDescription As String

sDescription = "SELECT
[Inventory06].[ID],[Inventory06].[Item],[Inventory06].[Description]" & _
"FROM Inventory06" & _
"WHERE [ID]=" & Me.cboItem.Value

Me.cboDescription.RowSource = sDescription
Me.cboDescription.Requery
End Sub


cboDescription:
RowSource: SELECT Inventory06.ID, Inventory06.Item, Inventory06.Description
FROM Inventory06;
 

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