Good Afternoon,
I am in the middle of creating a function that populates two unbound text boxes on a form and then uses those unbound textboxes in a query (Total of 3 unbound text boxes - 2 are populated from this function). The saved query object is working fine when I manually execute it (after the unbound text boxes have been populated). However, when I go to set the same query to a recordset I am getting the "Too Few Parameters. Expected 3." error message.
In the saved query I used the build function to use the unbound text boxes as part of the where clause.
Below is the code I am trying to execute:
Any ideas on this? The unbound text boxes are populated before the query is set to the recordset.
Thank you in advance for your help.
Tallman
I am in the middle of creating a function that populates two unbound text boxes on a form and then uses those unbound textboxes in a query (Total of 3 unbound text boxes - 2 are populated from this function). The saved query object is working fine when I manually execute it (after the unbound text boxes have been populated). However, when I go to set the same query to a recordset I am getting the "Too Few Parameters. Expected 3." error message.
In the saved query I used the build function to use the unbound text boxes as part of the where clause.
Below is the code I am trying to execute:
PHP:
Public Function Test()
Dim db As DAO.Database
Set db = CurrentDb
Dim rst As DAO.Recordset
Dim DtBegin As String
''FInd the Begin dt
stBegin = DateAdd("q", -1, DateSerial(Year(Date), (DatePart("q", Date) - 1) * 3 + 1, 1))
Dim DtEnd As String
''find the end date
DtEnd = DateAdd("Q", DateDiff("Q", 0, Date) - 1, 0)
''populate the unbound text with begin dt
Forms!frmConsultingMain!txtTrailBegin = Format(stBegin, "YYYYMMDD")
''populate the unbound text with end dt
Forms!frmConsultingMain!TxtTrailEnd = Format(DtEnd, "YYYYMMDD")
Set rst = db.OpenRecordset("qryTest") ''The saved query that works when executing directly.
If rst.RecordCount = 0 Then
MsgBox "no records"
Exit Function
End If
While Not rst.EOF
MsgBox rst.Fields(0)
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
End FUnction
Any ideas on this? The unbound text boxes are populated before the query is set to the recordset.
Thank you in advance for your help.