Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Error Run time 3061 for Multiple Search Request


Message #1 by "Rick N" <loonievisa@h...> on Thu, 22 Aug 2002 11:31:45 -0600
Situation:

My search form consist of 10 search fields.  If I check on one of the search 
field for the database to search it works fine (Eg. Source).

PROBLEM:
When I do multiple searches (eg. Source + Location) an error occurs 
displaying.

"Run time error 3061. Too few parameters. Expected1"

Debug takes me to the line... Set rec = qryDef.OpenRecordset


Here's my code:
Dim sql_string As String
Dim str_where As String
Dim qryDef As DAO.QueryDef
Dim rec As Recordset
Dim response As Integer

   Set qryDef = CurrentDb.QueryDefs("qry_source")

    ' If user decides to search by source
    sql_string = "select * from [tbl_DrawingInfo] where"

    '1.  Search by source
    If Me.chk_source = True Then

            str_where = str_where & _
                " and (tbl_DrawingInfo.Source)= '" & Me.cbo_source & "'"
    End If


' strip off the "and" from the where clause
    If Len(sql_string) > 0 Then
        str_where = Mid$(str_where, 5)
        sql_string = sql_string & str_where
    End If


    'sql_string = qryDef.SQL
    qryDef.SQL = sql_string
    Set rec = qryDef.OpenRecordset

    If rec.EOF = False Then

        'MsgBox rec!Source
        'Display message that record(s) is/are found
        MsgBox ("Record found"), vbOKOnly, "Result"

        qryDef.Close
        RefreshDatabaseWindow

        ' Open report to display results
        DoCmd.OpenReport "rpt_DrawingInfo", acViewPreview, , str_where

' strip off the "and" from the where clause
    If Len(sql_string) > 0 Then
        str_where = Mid$(str_where, 5)
        sql_string = sql_string & str_where
    End If


    'sql_string = qryDef.SQL
    qryDef.SQL = sql_string
    Set rec = qryDef.OpenRecordset

    If rec.EOF = False Then

        'MsgBox rec!Source
        'Display message that record(s) is/are found
        MsgBox ("Record found"), vbOKOnly, "Result"

        qryDef.Close
        RefreshDatabaseWindow

        ' Open report to display results
        DoCmd.OpenReport "rpt_DrawingInfo", acViewPreview, , str_where

    Else


Thank you for the help!
Rick

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

Message #2 by "Amy Wyatt" <amyw@c...> on Thu, 22 Aug 2002 20:59:39
I don't see where you add another search criteria to your code so I am not 
sure where your error is occuring and I don't know your field names in the 
table tbl_DrawingInfo but the error you are getting is generally because a 
field name is spelled incorrectly. When concatinating to build an SQL you 
really have to be wary of spaces being put in the correct places or you 
can get errors. 

I would put a break in the code at "qryDef.SQL = sql_string" and then 
bring up the debug window, type ?sql_string and hit enter. This will show 
you your SQL syntax. Then copy this line and paste it into a new query and 
go to design view. Look for a field with [] around it in the field row. 
This will tell you where the query is getting confused.

Amy

> Situation:

My search form consist of 10 search fields.  If I check on one of the 
search 
field for the database to search it works fine (Eg. Source).

PROBLEM:
When I do multiple searches (eg. Source + Location) an error occurs 
displaying.

"Run time error 3061. Too few parameters. Expected1"

Debug takes me to the line... Set rec = qryDef.OpenRecordset


Here's my code:
Dim sql_string As String
Dim str_where As String
Dim qryDef As DAO.QueryDef
Dim rec As Recordset
Dim response As Integer

   Set qryDef = CurrentDb.QueryDefs("qry_source")

    ' If user decides to search by source
    sql_string = "select * from [tbl_DrawingInfo] where"

    '1.  Search by source
    If Me.chk_source = True Then

            str_where = str_where & _
                " and (tbl_DrawingInfo.Source)= '" & Me.cbo_source & "'"
    End If


' strip off the "and" from the where clause
    If Len(sql_string) > 0 Then
        str_where = Mid$(str_where, 5)
        sql_string = sql_string & str_where
    End If


    'sql_string = qryDef.SQL
    qryDef.SQL = sql_string
    Set rec = qryDef.OpenRecordset

    If rec.EOF = False Then

        'MsgBox rec!Source
        'Display message that record(s) is/are found
        MsgBox ("Record found"), vbOKOnly, "Result"

        qryDef.Close
        RefreshDatabaseWindow

        ' Open report to display results
        DoCmd.OpenReport "rpt_DrawingInfo", acViewPreview, , str_where

' strip off the "and" from the where clause
    If Len(sql_string) > 0 Then
        str_where = Mid$(str_where, 5)
        sql_string = sql_string & str_where
    End If


    'sql_string = qryDef.SQL
    qryDef.SQL = sql_string
    Set rec = qryDef.OpenRecordset

    If rec.EOF = False Then

        'MsgBox rec!Source
        'Display message that record(s) is/are found
        MsgBox ("Record found"), vbOKOnly, "Result"

        qryDef.Close
        RefreshDatabaseWindow

        ' Open report to display results
        DoCmd.OpenReport "rpt_DrawingInfo", acViewPreview, , str_where

    Else


Thank you for the help!
Rick

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


  Return to Index