I'm relatively new to Access/VBA and am trying to do an INSERT command into a table that has an auto number for a primary key.
As this value is an auto number, I'd like Access to chose it for me.
However, as this is the PK, and it's a required field, I believe Access won't let me do an INSERT unless I specify it...
So here's my INSERT statement:
DoCmd.RunSQL _
"INSERT INTO CoursesDates
(courseID, dateOffered, time, hours, seats)
VALUES (" & Me!cboCourse & ", #" & Me!txtDateOffered & "#,
" & Me!txtTime & ", " & Me!txtHours & ", " & Me!txtSeats & ")"
(I broke this up for readability, but in the code the entire sting is on one line)
The table I'm inserting into has only ONE other field: CoursesDatesID, which is an auto number.
Running this code generates a syntax error.
I've run other INSERT queries that worked, the only difference being that for the working queries, I was able to specify ALL fields, whereas for this query I need Access to provide the number automatically.
Any thoughts?
Thanks in advance!
As this value is an auto number, I'd like Access to chose it for me.
However, as this is the PK, and it's a required field, I believe Access won't let me do an INSERT unless I specify it...
So here's my INSERT statement:
DoCmd.RunSQL _
"INSERT INTO CoursesDates
(courseID, dateOffered, time, hours, seats)
VALUES (" & Me!cboCourse & ", #" & Me!txtDateOffered & "#,
" & Me!txtTime & ", " & Me!txtHours & ", " & Me!txtSeats & ")"
(I broke this up for readability, but in the code the entire sting is on one line)
The table I'm inserting into has only ONE other field: CoursesDatesID, which is an auto number.
Running this code generates a syntax error.
I've run other INSERT queries that worked, the only difference being that for the working queries, I was able to specify ALL fields, whereas for this query I need Access to provide the number automatically.
Any thoughts?
Thanks in advance!