Problem in building dynamic query

J

Jack

Hi,
I am building a dynamic sql string in access
sql = " INSERT INTO tblExpense (ENO, EntryDate, ContractedServiceExpense, "
sql = sql & "TravelExpense, PersonnelExpense)"
sql = sql & " VALUES('" & l_ENO & "', '" & l_Date & "', " &
l_contractedserviceexpense & ", " & l_travelexpense & ", " &
l_personnelexpense & ")"
However, the date field is not working properly due to error. Any help is
appreciated. Thanks in advance. Regards.
 
D

Douglas J. Steele

Dates need to be delimited with # characters and the date must either be in
mm/dd/yyyy format (regardless of what your regional settings are) or an
unambiguous format such as yyyy-mm-dd or dd mmm yyyy.

My normal approach combines these in a single Format statement:

sql = " INSERT INTO tblExpense (ENO, EntryDate, ContractedServiceExpense, "
sql = sql & "TravelExpense, PersonnelExpense)"
sql = sql & " VALUES('" & l_ENO & "', " & Format(l_Date,
"\#mm\/dd\/yyyy\#") & ", " &
l_contractedserviceexpense & ", " & l_travelexpense & ", " &
l_personnelexpense & ")"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top