W
wrightlife11
I am trying to get the earliest date of a set of records. I can't use last
or first because the records came into the database with no correlation to
the dates.
I wrote this code to find the answer, but it has a problem getting
information from the form control that the SQL states.
Why does this code not work? I get a runtime error '3061'. Too Few
Parameters. Expected 1.
When I put a value( ie.'5132053') in the WHERE clause instead of the form
control it works fine, but I need to limit the parameters to the form control.
The form is open and the control has data like the value above. I tried to
use the results of the combo box since it is filtering records in the data
set, but that did not work either.
Public Function EarlyFlameOnShapes() As Date
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim dte As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT tblMain.*,
IIf(IsNull([SFStartDate]),'9/9/9999',[SFStartDate])) AS StartDate " & _
"FROM tblMain " & _
"WHERE (((tblMain.FabDoc) Like " & _
"Forms!frmFabDocCheckOff!cmboFabDoc));")
rst.MoveFirst
dte = rst![StartDate]
While Not rst.EOF
dte = rst![StartDate]
If rst![StartDate] < dte Then
dte = rst![StartDate]
End If
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
EarlyFlameOnShapes = dte
End Function
or first because the records came into the database with no correlation to
the dates.
I wrote this code to find the answer, but it has a problem getting
information from the form control that the SQL states.
Why does this code not work? I get a runtime error '3061'. Too Few
Parameters. Expected 1.
When I put a value( ie.'5132053') in the WHERE clause instead of the form
control it works fine, but I need to limit the parameters to the form control.
The form is open and the control has data like the value above. I tried to
use the results of the combo box since it is filtering records in the data
set, but that did not work either.
Public Function EarlyFlameOnShapes() As Date
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim dte As Variant
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT tblMain.*,
IIf(IsNull([SFStartDate]),'9/9/9999',[SFStartDate])) AS StartDate " & _
"FROM tblMain " & _
"WHERE (((tblMain.FabDoc) Like " & _
"Forms!frmFabDocCheckOff!cmboFabDoc));")
rst.MoveFirst
dte = rst![StartDate]
While Not rst.EOF
dte = rst![StartDate]
If rst![StartDate] < dte Then
dte = rst![StartDate]
End If
rst.MoveNext
Wend
rst.Close
Set rst = Nothing
EarlyFlameOnShapes = dte
End Function