Access VBA - Date as text converts to a math division when copied

icyrius

New Member
Joined
Dec 22, 2012
Messages
15
Hello experts,

I have a text date (7/1/2015) that when copied to another table converts as a math division and pastes an integer (3.47394540942928E-03). The receiving table has been formatted to be also a text field.

This the part of the code where is pasting the record set,
Code:
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tbl_DatesbyLocation (Location,Start_Date,End_Date) VALUES (" & recordset1.Fields(0).Value & "," & recordset2.Fields(0).Value & "," & recordset2.Fields(1).Value & ")"
recordset1.MoveNext

The source table (recordset2) has dates entered as text.

Thanks for the help.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
ON the general principle that string data needs to be enclosed in quotes, I would try:
"'" & recordset2.Fields(1).Value & "'"

Remember that you are creating a raw SQL string here, which is simply run as such.
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top