Hi all
I have been having a problem trying to enter a date in a table using vba. I have fixed it now, but can anyone shed any light as to why my two examples use the date format differently but both work???
I know that vba uses the american date format but surely, it should remain the same no matter what type of procedure you are running.
Please see my examples.
Using the db.Execute method I have had to specify the date format as "mm/dd/yyyy" and also use the #
Using a recordset I just have to use the expected format of "dd/mm/yyyy" and no #
I thought this may be different for just recordsets, so I tested using a SELECT statement. I had to use the "mm/dd/yyyy" format and #... Confused!
Why does it do this or is there something I need to do so that I can just use the same format throughout my code.
Thanks
I have been having a problem trying to enter a date in a table using vba. I have fixed it now, but can anyone shed any light as to why my two examples use the date format differently but both work???
I know that vba uses the american date format but surely, it should remain the same no matter what type of procedure you are running.
Please see my examples.
Using the db.Execute method I have had to specify the date format as "mm/dd/yyyy" and also use the #
Code:
Sub dateEntry1()
Dim db As DAO.Database
Set db = CurrentDb
' date is entered in the format dd/mm/yyyy
myDate = InputBox("Please enter date", "Date required")
db.Execute "Update tblDate Set runDate = #" & Format(myDate, "mm/dd/yyyy") & "#", dbFailOnError
End Sub
Code:
Sub dateEntry2()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblDate")
' date is entered in the format dd/mm/yyyy
myDate = InputBox("Please enter date", "Date required")
rs.Edit
rs(0) = Format(myDate, "dd/mm/yyyy")
rs.Update
rs.Close
db.Close
End Sub
Code:
Sub DateFind()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
' date is entered in the format dd/mm/yyyy
myDate = InputBox("Please enter date", "Date required")
Set rs = _
db.OpenRecordset("SELECT * FROM tblDate WHERE runDate = #" & Format(myDate, "mm/dd/yyyy") & "#")
MsgBox rs.RecordCount
rs.Close
db.Close
End Sub
Why does it do this or is there something I need to do so that I can just use the same format throughout my code.
Thanks