Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Posts
    110

    Unanswered: Query parameter problem

    Hello everybody

    Let`s start at the beginning. Simply stated, I have a form with a text box on it. There also exists a push button. When the push button is pressed an event handler responds. In the event handler I need to get a recordset returned after calling a query with a single parameter. The parameter is supposed to be read from the text box on the form. The code goes like this :

    Private Sub btnReport_Click()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset

    Set db = CurrentDb()
    Set rst = db.OpenRecordset("query_Anafora_bash_aitias_blabhs ")
    On Error GoTo no_record

    rst.MoveLast
    On Error GoTo 0
    rst.Close
    Set rst = Nothing
    Set db = Nothing

    If IsDate(Me.From_Date) Then dtFrom_Date = Me.From_Date
    If IsDate(Me.To_Date) Then dtTo_Date = Me.To_Date

    If (Me.btnKakh_xrhsh) Then
    DoCmd.OpenReport "Anafora_bash_aitias_blabhs_kakh_xrhsh", acViewPreview
    Else
    DoCmd.OpenReport "Anafora_bash_aitias_blabhs_fysiologikh_f8ora" , acViewPreview
    End If

    Exit Sub

    no_record:
    MsgBox ("Δεν βρέθηκαν εγγραφές")

    End Sub

    The statement
    Set rst = db.OpenRecordset("query_Anafora_bash_aitias_blabhs ")

    fails with a 'too few parameters' error.

    Note : When I built the form, I inserted something like [Forms].[Episkeyh_bash_aitias_blabhs].[btnKakh_xrhsh] in the Criteria section of the MS Access Query designer.

    Any suggestions?

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try to use
    [Forms]![Episkeyh_bash_aitias_blabhs].[btnKakh_xrhsh]

  3. #3
    Join Date
    Dec 2002
    Location
    Glasgow, UK
    Posts
    100
    you have to handle the parameters when using code to open a query.


    dim prm as dao.parameter
    dim qdf as dao.querydef

    set qdf = db.querydefs("query_Anafora_bash_aitias_blabhs")

    for each prm in qdf.parameters
    prm.value = eval(prm.name)
    next prm

    set rst = qdf.openrecordset
    Last edited by xander; 04-28-04 at 09:40.
    Access XP & WinXP Pro

  4. #4
    Join Date
    Apr 2004
    Posts
    110
    Will the querydef create a new brand new query? I already have the query defined and would not like it to be overwritten.

    George Papadopoulos

  5. #5
    Join Date
    Dec 2002
    Location
    Glasgow, UK
    Posts
    100
    no don't worry it just references the query you have created.
    Last edited by xander; 04-28-04 at 09:39.
    Access XP & WinXP Pro

  6. #6
    Join Date
    Apr 2004
    Posts
    110
    thx, xander

    that actually worked!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •