On button click, what i'm trying to do is (in steps)
[tblPayMonths] contains the following sample data:
I have the following code:
As you can see all dates are held in the table in the format dd/mm/yyyy.
However, when i try to query my table using the above SQL statement i am receiving the error message: "Item not found in this collection"
I have noticed when created as an access query with the parameter '01/06/2008' the SQL automatically produced swaps the date into US format like this.....
.....so i believe this is where it is failing.
I'm really confused here about the formats, and why it would change back to US when all dates are stored as UK short dates. Can anyone suggest an alternative as i'm well and truely perplexed.
- Find Current Date [Date]
- Return First Date of Current Month [New_Date] (Eg: 10/06/2008 would become 01/06/2008)
- Use [New_Date] in a query to pull out [tblPayMonths].[MONTH_ID]
- Reflect [MONTH_ID] in a field on a form called txtMonthID.
[tblPayMonths] contains the following sample data:
Code:
MONTH_ID SESS MONTH MONTH_START_DATE MONTH_END_DATE 07-JUN08 07 JUN 01/06/2008 30/06/2008 07-JUL08 07 JUL 01/07/2008 31/07/2008 08-AUG08 08 AUG 01/08/2008 31/08/2008 08-SEP08 08 SEP 01/09/2008 30/09/2008
Code:
Private Sub cmdTest_Click()
On Error GoTo Err_cmdTest_Click
Dim dbsCTrack As DAO.Database
Dim rstGenerateMonthID As DAO.Recordset
Dim sqlGenerateMonthID As String
Dim NewDate As Date
NewDate = DateSerial(Year(Date), Month(Date), 1)
Me.txtMonthID = NewDate
Set dbsCTrack = CurrentDb
sqlGenerateMonthID = "SELECT month_id FROM tblPayMonths WHERE (((month_start_date)=#" & NewDate & "#))"
Set rstGenerateMonthID = dbsCTrack.OpenRecordset(sqlGenerateMonthID)
MsgBox sqlGenerateMonthID
Me.txtMonthID = rstGenerateMonthID(1)
rstGenerateMonthID.Close
Exit_cmdTest_Click:
Exit Sub
Err_cmdTest_Click:
MsgBox Err.Description
Resume Exit_cmdTest_Click
End Sub
However, when i try to query my table using the above SQL statement i am receiving the error message: "Item not found in this collection"
I have noticed when created as an access query with the parameter '01/06/2008' the SQL automatically produced swaps the date into US format like this.....
Code:
SELECT tblPayMonths.MONTH_ID FROM tblPayMonths WHERE (((tblPayMonths.MONTH_START_DATE)=#6/1/2008#));
I'm really confused here about the formats, and why it would change back to US when all dates are stored as UK short dates. Can anyone suggest an alternative as i'm well and truely perplexed.
Comment