adding a record using SQL

  • Thread starter Thread starter Lindsey M
  • Start date Start date
L

Lindsey M

Hi everyone, hope this finds you well :o)

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
 
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 & "#)"
 
Back
Top