Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Parameter expected when I try to run a query


Message #1 by "Antony Peel" <Antony.Peel@m...> on Fri, 21 Dec 2001 11:57:28
I have written a query that gets the maximum item line number for an 

enquiry.  I am trying to create a record set so that I can increment the 

last item line number of the enquiry when I add a new record.



I keep getting a message that the query needs a parameter.  The query runs 

OK and returns the correct result, but I can't get it to work with the 

code below. 



Private Sub AddEnqLineBut_Click()

On Error GoTo Err_AddEnqLineBut_Click

        

    Dim rs As Recordset

    

    Dim lastnum As Integer

    Dim newNum As Integer

        

    Set rs = CurrentDb.OpenRecordset("MaxItemQuery")

    'open query to find last line number for this enq num

        

    lastnum = rs!MaxOfEnqItemNo

    ' Assign last number to variable

    

    newNum = lastnum + 1

    ' Create new number for new record

    

    DoCmd.GoToRecord , , acNewRec

    Me.EnqItemNo = newNum



Exit_AddEnqLineBut_Click:

    Exit Sub



Err_AddEnqLineBut_Click:

    MsgBox Err.Description

    Resume Exit_AddEnqLineBut_Click
Message #2 by "Tim Nemec" <tim@n...> on Fri, 21 Dec 2001 14:52:07
Do any of the table names used in the query have hyphens ("-")

in their name? That has caused a similar problem for me in the 

past under ADO but I'm not certain it is a problem under DAO. The

query will run fine from Access but not from the code. Just a thought...
Message #3 by "Alan Douglas" <aland@a...> on Sat, 22 Dec 2001 08:58:45
If the query has a typo in it where a field name is specified, the 

interpreter will think it's a parameter that you're going to provide at 

run time. (I'm assuming you get a pop-up box asking for the value of the 

parameter ... You were kind of vague in specifying the message you got.)

  Return to Index