pengiliverpool
New member
- Local time
- Today, 19:33
- Joined
- Nov 18, 2009
- Messages
- 8
i have created a recordset from a table and then using user input as start date and end date i take a record count of the record set. the code works ok but the count it returns is not correct is certain instances.
i have copied the code into a query and the results there are fine but they are from the actual table not a recordset of the table. does anyone have any experience of passing date variables into recordsets?
my code is as follows:
Private Sub Form_Load()
Dim Db As DAO.Database
Dim rstable As DAO.Recordset
Dim Date1 As Date
Dim Date2 As Date
Date1 = Form_Menu.Combo1.Value
Date2 = Form_Menu.Combo2.Value
Dim sResults As String
Set Db = CurrentDb
Set rstable = Db.OpenRecordset("Saved_Data", dbOpenDynaset)
sResults = "SELECT * FROM Saved_Data WHERE (((Saved_Data.A5)> #" & Date1 & "# And (Saved_Data.A5) < #" & Date2 & "# ));"
Set rstable = Db.OpenRecordset(sResults, dbOpenDynaset)
If rstable.EOF = False Then
rstable.MoveLast
num1 = rstable.RecordCount
Else
num1 = "0"
End If
Text1.Value = num1
when i ask for januarys records so start date 1st jan and end date 31st it gives correct number. when i change to 31st dec and 1 feb which should give same result it gives the figure as 0
if anyone could help that would be brilliant i have been working on this for days now
i have copied the code into a query and the results there are fine but they are from the actual table not a recordset of the table. does anyone have any experience of passing date variables into recordsets?
my code is as follows:
Private Sub Form_Load()
Dim Db As DAO.Database
Dim rstable As DAO.Recordset
Dim Date1 As Date
Dim Date2 As Date
Date1 = Form_Menu.Combo1.Value
Date2 = Form_Menu.Combo2.Value
Dim sResults As String
Set Db = CurrentDb
Set rstable = Db.OpenRecordset("Saved_Data", dbOpenDynaset)
sResults = "SELECT * FROM Saved_Data WHERE (((Saved_Data.A5)> #" & Date1 & "# And (Saved_Data.A5) < #" & Date2 & "# ));"
Set rstable = Db.OpenRecordset(sResults, dbOpenDynaset)
If rstable.EOF = False Then
rstable.MoveLast
num1 = rstable.RecordCount
Else
num1 = "0"
End If
Text1.Value = num1
when i ask for januarys records so start date 1st jan and end date 31st it gives correct number. when i change to 31st dec and 1 feb which should give same result it gives the figure as 0
if anyone could help that would be brilliant i have been working on this for days now