Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT QUERY 3

Status
Not open for further replies.

manny1234

IS-IT--Management
Mar 13, 2006
58
US
I need to be able to insert a date into a table with a VB script in access like so...

Code:
DoCmd.RunSQL "INSERT INTO History (MID,Date) SELECT " & Me![Merchant ID Number] & ",Date()"

Not sure how to set up the syntax
 
How about:
[tt]DoCmd.RunSQL "INSERT INTO History (MID,Date) SELECT " & Me![Merchant ID Number] & ", #" & Date() & "#"[/tt]
 
Try the following string:

[tt]"INSERT INTO History ([MID],[Date]) Values (" & Me![Merchant ID Number] & ",Date())"[/tt]

Note - both mid and date are reserved words, they are both functions, and shouldn't be used as names of objects. Using bracketes might be a sufficient workaround.

Roy-Vidar
 
You are attempting to INSERT from variables in your system ... not from a table as implied by SELECT ...
Code:
DoCmd.RunSQL "INSERT INTO History (MID,Date) " & _
" VALUES(" & Me![Merchant ID Number] & ", #" & Date() & "#)"
 
excellent thanks!
Code:
DoCmd.RunSQL "INSERT INTO History ([MID],[Date]) VALUES (" & Me![Merchant ID Number] & ",#" & Date & "#)"
... did the trick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top