Skip to content
Advertisement

Access VBA: SQL String with string tablefield converted as date

Normally I figure out my DateTime issues in VBA and SQL by trial and error, but in this case I have hit a wall.

I am not even sure I can do what I want.

I have a temporary table with fields F1, F2, etc.

Field F7 contains a date as a string n the format dd/MM/yyyy.

Now, I want to copy the data from the temporary table, to a table where the data in field F7 should be stored in a Date/Time field. The format of this field is Short Date (dd-MM-yyyy).

I have tried using CDate(), Format() and Trim() alone and in several combinations, along with padding my date data with ## and adding brackets [] to my table fieldname, but I simply cannot find the correct combination.

This is my code. The importedDate works fine because I am using a variable. But for the field F7, I am mixing the SQL query with the VBA date conversion, and it is not working for me:

Any help would be much appreciated. I am using Access 2013.

Thanks.

Advertisement

Answer

It’s really quite simple:

or, if F7 is dotted (corrected to have single-quotes with Replace):

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement