Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter query will not work! 2

Status
Not open for further replies.

TimMorris

Programmer
Sep 10, 2000
2
AU
I have a select query with the following as criterion for a date field:
Code:
Between [Forms]![myForm]![StartDate] And [Forms]![myForm]![EndDate]
A second query performs agregate sums on the first query. The query works fine if I run it using the access user interface, but fails from within VB code!
Code:
Set dbs = CurrentDB
Set rec = dbs.OpenRecordset("myAggregateQuery", dbOpenSnapshot)
I get "run time error 3061 - too few parameters. Expected 2."

If I delete the date criterion, or change it with hardwired #dates#, it works fine. What am I doing wrong?

Cheers,
Tim Morris
tim.morris@utas.edu.au
[sig][/sig]
 
Put your dates in as function calls this will work under all conditions.

Public glbBegDate As Date
Public glbEndDate As Date

Function ReturnBegDate() As Date
' Return the Begin Date
ReturnBegDate = glbBegDate
End Function

Function ReturnEndDate() As Date
' Return the End Date
ReturnEndDate = glbEndDate
End Function

Between ReturnBegDate() And ReturnEndDate()

Put the functions and the variables in your standard module and load the variables before you do the query. [sig][/sig]
 
Cmmrfrds,

Thanks heaps, I tried your solution and it worked perfectly! Thanks again.

Tim. [sig][/sig]
 
It pays to search through old postings. This was exactly what I needed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top