SQL Query using WHERE and AND 
Author Message
 SQL Query using WHERE and AND

Sorry if this appears twice.  I got a page fault when I posted the
first time and don't know if it went through.

I am trying to use an SQL query to create a recordset using parameters
from two drop down boxes.

DIM strSQL as string

strSQL="Select * FROM MyFile WHERE IDCategory=" & _
           cboIndex.ItemData (cboIndex.ListIndex) & _
           "AND LanguageID=" &
cboLanguage.ItemData(cboLanguage.ListIndex)

datMain.Recordsource=strSQL
datMain.Refresh

I get an error "Too few parameters. Expected 1"

Without the AND and the second condition it works fine.  How can I use
more than one condition to get the recordset I want?

Thanks,

Scott



Fri, 10 Sep 2004 20:46:46 GMT  
 SQL Query using WHERE and AND
It may be because you have no space before the AND.

Just a thought.

Wuxapian.

Quote:
> Sorry if this appears twice.  I got a page fault when I posted the
> first time and don't know if it went through.

> I am trying to use an SQL query to create a recordset using parameters
> from two drop down boxes.

> DIM strSQL as string

> strSQL="Select * FROM MyFile WHERE IDCategory=" & _
>            cboIndex.ItemData (cboIndex.ListIndex) & _
>            "AND LanguageID=" &
> cboLanguage.ItemData(cboLanguage.ListIndex)

> datMain.Recordsource=strSQL
> datMain.Refresh

> I get an error "Too few parameters. Expected 1"

> Without the AND and the second condition it works fine.  How can I use
> more than one condition to get the recordset I want?

> Thanks,

> Scott



Fri, 10 Sep 2004 21:11:08 GMT  
 SQL Query using WHERE and AND

See inline..

Quote:
>I am trying to use an SQL query to create a recordset using parameters
>from two drop down boxes.

>DIM strSQL as string

>strSQL="Select * FROM MyFile WHERE IDCategory=" & _
>           cboIndex.ItemData (cboIndex.ListIndex) & _
>           "AND LanguageID=" &
>cboLanguage.ItemData(cboLanguage.ListIndex)

if MsgBox ("Are you sure you want to execute" & vbcrlf & strSQL & _
        " ?", vbYesno, "Take a good look at the spaces !!!") = vbYes Then

Quote:
>datMain.Recordsource=strSQL
>datMain.Refresh

End If

Quote:
>I get an error "Too few parameters. Expected 1"

Basicly if your combo1 is "Hello" and your combo2 is "world" then
your strSQL would look like this.. :
Select * FROM MyFile WHERE IDCategory=HelloAND  LanguageID=world

HTH

Regards, Frank



Sat, 11 Sep 2004 00:06:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Executing SQL queries using modules via Jet

2. SQL queries using VB

3. SQL Query using variables

4. vbscript and SQL Query using 'LIKE'

5. How to pass a new SQL query using the DATAEnvironment

6. parameters to a sql query, used with Crystal Reports

7. How to use variables in a sql query using VBA

8. SQL queries, using BETWEEN operator

9. HELP! DAO and sql queries using Double datatypes

10. Help with SQL query using LIKE and variable field

11. Executing SQL queries using modules via Jet

12. SQL query using a variable

 

 
Powered by phpBB® Forum Software