-
I receive the error: Too few parameters. Expected 2. when I run the below code. I have never written a parameter in VB can someone help me out with what is wrong with the below code?
Data1.RecordSource = "PARAMETERS [FROM DATE] DateTime [TO DATE] DateTime;"
Data1.RecordSource = "SELECT * from MASTER where DATE_OPENED between [FROM DATE] AND [TO DATE]"
-
Data1.RecordSource = "PARAMETERS [FROM DATE] DateTime [TO DATE] DateTime;"
Data1.RecordSource = "SELECT * from MASTER where DATE_OPENED between [FROM DATE] AND [TO DATE]"
You will need to do something like this
"SELECT * FROM MASTER WHERE DATE_OPENED between " & [FROM DATE] & " AND " [TO DATE]"
-
This syntax does not seem to work in VB so if anyone could help out i would appreciate it; thanks!!!
-
Hi, there.
I didn't figure out how to use Parameter object with Data control. But there is another way:
Code:
Dim sql As String
sql = "Select OrderId,CustomerId from orders where orderdate between " & _
Chr(35) & Text1 & Chr(35) & " and " & Chr(35) & Text2 & Chr(35) 'Chr(35) is #
Data1.RecordSource = sql
Data1.Refresh
Larisa
-
OK. I found how to use Parameters. I use NorthWind db
Code:
Dim str As String
Dim qdf As QueryDef
str = "PARAMETERS [Beginning OrderDate] DateTime, " _
& "[Ending OrderDate] DateTime; SELECT * FROM Orders " & _
"WHERE (OrderDate Between[Beginning OrderDate] " _
& "And [Ending OrderDate]);"
Set qdf = Data1.Database.CreateQueryDef("", str)
qdf.Parameters![Beginning OrderDate] = CDate(Text1)
qdf.Parameters![Ending OrderDate] = CDate(Text2)
Set Data1.Recordset = qdf.OpenRecordset
Data1.Recordset.MoveLast
Data1.Recordset.Close