adding a record using SQL

L

Lindsey M

Hi everyone, hope this finds you well :eek:)

I have form that contains info relating to a table. What i want to do is
insert the info from the form, into the table by using the INSERT
INTOfunction of SQL.

This is what i have so far:

DoCmd.RunSQL "INSERT INTO tblSchedule (UserID, RoomID, Date, StartTime,
EndTime) VALUES ('sUserID', 'sRoomID', 'dDate', 'StartTime', 'EndTime');"

but this just brings up an error?

I'me very new to access and even newer to SQL so any help would be
gratefully appreciated

Cheers
Lindsey
 
D

Duane Hookom

Your SQL would add a record that assumes all fields are text. A guess at
data types would change your code to
DoCmd.RunSQL "INSERT INTO tblSchedule " & _
"(UserID, RoomID, Date, StartTime, EndTime) " & _
"VALUES (" & sUserID & ", " & sRoomID & ", #" & _
dDate & "#, #" & StartTime & "#, #" & EndTime & "#)"
 

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