Hello All,
I am sure you all know about this function from the Northwind 2.0. I copied the function code from the db of both (StringFormat & StringFormatSql). I have been using this for INSERT INTO & UPDATE in VBA. There were no issues. But, when I used for one of my table it gave me 3464 error on date fields. Below is the code.
Debug.Print gave this result.
When I replaced the function with regular concatenate method (shown below) it works just fine. No 3464 error.
The issue was on date fields. BUT the first method works on other tables, even UPDATE on Date field, no 3464 error.
So I am confused now. I am seeking for your expeienced advice, since the final product will be used by different users on different machines. What is the safest method? Should I replace StringFormatSql/ToAccessDate method with regular concatenate method?
Formats:
txtDate = "mmm d, yyyy"
LoadDate - Date/Time
IsActive - Number (Byte)
ModifiedOn - Date/Time
PKID - Number (Long Integer)
Office version: 2021
Working on Front End.
I am sure you all know about this function from the Northwind 2.0. I copied the function code from the db of both (StringFormat & StringFormatSql). I have been using this for INSERT INTO & UPDATE in VBA. There were no issues. But, when I used for one of my table it gave me 3464 error on date fields. Below is the code.
Code:
strSql = StringFormatSQL("UPDATE tblName SET LoadDate = {0}, IsActive ={1}, ModifiedOn ={2} WHERE PKID = {3} And IsActive = {4};", ToAccessDate(Me.txtDate - 1), 0, ToAccessDate(Now), Me.cboPK, 1)
CurrentDb.Execute strSql, dbFailOnError
Debug.Print gave this result.
Code:
UPDATE tblName SET LoadDate = '2023-10-20', IsActive =0, ModifiedOn ='2023-10-20 11:44:01' WHERE PKID = '4' And IsActive = 1
When I replaced the function with regular concatenate method (shown below) it works just fine. No 3464 error.
Code:
strSql = "UPDATE tblName SET LoadDate =#" & Format(Me.txtDate - 1, "yyyy-mm-dd") & "#, IsActive =0, ModifiedOn =Now WHERE PKID =" & Me.cboPK & " And IsActive =1;"
CurrentDb.Execute strSql, dbFailOnError
The issue was on date fields. BUT the first method works on other tables, even UPDATE on Date field, no 3464 error.
So I am confused now. I am seeking for your expeienced advice, since the final product will be used by different users on different machines. What is the safest method? Should I replace StringFormatSql/ToAccessDate method with regular concatenate method?
Formats:
txtDate = "mmm d, yyyy"
LoadDate - Date/Time
IsActive - Number (Byte)
ModifiedOn - Date/Time
PKID - Number (Long Integer)
Office version: 2021
Working on Front End.
Code:
Public Function ToAccessDate(ByVal dt As Date) As String
ToAccessDate = Format(dt, "yyyy-mm-dd hh:nn:ss")
End Function