Cascading Combo

H

Herman Wellington

Hi,

I learned the Cascading Combo from below link

http://bytes.com/forum/thread605958.html

and made the following Afterupdate Event

With Me!(matcode)
If IsNull (Me!matcat) Then
.RowRource = ""
Else
.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]=" Me!matcat
Endif
Call .Requery
Endwith

The only different of the Tutor's example and my work is they look up a [ID]
and I look up [matcat] which is a text. The code above couldn't automatic
fill in the query to come up with result.

How can I chance, may be the list line, to solve the problem.

Thanks.

Herman W.
 
D

Daniel Pineault

You forgot an '&' in the Where statement of your query and if matcat is
textual then the search criteria should be between ''. So try:

With Me!(matcode)
If IsNull (Me!matcat) Then
.RowRource = ""
Else
.RowRource = "SELECT [matcode] " & _
"FROM matdetail " & _
"WHERE [matcat]='" & Me!matcat & "'"
Endif
Call .Requery
Endwith

--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
D

Douglas J. Steele

You need to put quotes around the text:

With Me!matcode
If IsNull (Me!matcat) Then
.RowRource = ""
Else
.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]='" & .Value & "'"
End If
Call .Requery
End With

Exagerated for clarity, that's

.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]= ' " & .Value & " ' "

Note that that assumes there are no apostrophes in what's in matcot. If
there are, you may need

.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]= " " " & .Value & " " " "

although that will fail if there are double quotes in what's in matcot.
 
H

Herman Wellington

Thanks buddy. You are the man.

Douglas J. Steele said:
You need to put quotes around the text:

With Me!matcode
If IsNull (Me!matcat) Then
.RowRource = ""
Else
.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]='" & .Value & "'"
End If
Call .Requery
End With

Exagerated for clarity, that's

.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]= ' " & .Value & " ' "

Note that that assumes there are no apostrophes in what's in matcot. If
there are, you may need

.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]= " " " & .Value & " " " "

although that will fail if there are double quotes in what's in matcot.


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Herman Wellington said:
Hi,

I learned the Cascading Combo from below link

http://bytes.com/forum/thread605958.html

and made the following Afterupdate Event

With Me!(matcode)
If IsNull (Me!matcat) Then
.RowRource = ""
Else
.RowRource = "Select [matcode] " & _
"From matdetail " & _
"Where [matcat]=" Me!matcat
Endif
Call .Requery
Endwith

The only different of the Tutor's example and my work is they look up a
[ID]
and I look up [matcat] which is a text. The code above couldn't automatic
fill in the query to come up with result.

How can I chance, may be the list line, to solve the problem.

Thanks.

Herman W.
 

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