Insert a record in a table

B

Brian

I am tring to insert some data from a form to a table:

INSERT BOOKING([Blocked Booked], [Teacher's Initials],
[Booking Date])
VALUES(forms![SINGLE BOOKING DETAIL]![Blocked Booked],
forms![SINGLE BOOKING DETAIL]![Teacher's Initials],
[Current Date])

but get a compile error expecting: =.

Have I got the wrong format for inserting a record, or is
there another syntax problem?

I want to insert the current date in the last field. Is
there something I put instaed of current date?

The primary key of Booking is [Booking ID]with a Data Type
of AutoNumber

Thanks guys
 
T

tina

if [Current Date] is not a control on your form, then the reference is
invalid. if you want to insert the current today's date, then try Date()
instead.

hth
 
J

John Vinson

I am tring to insert some data from a form to a table:

INSERT BOOKING([Blocked Booked], [Teacher's Initials],
[Booking Date])
VALUES(forms![SINGLE BOOKING DETAIL]![Blocked Booked],
forms![SINGLE BOOKING DETAIL]![Teacher's Initials],
[Current Date])

but get a compile error expecting: =.

Have I got the wrong format for inserting a record, or is
there another syntax problem?

I suspect that you're mixing SQL and VBA - they are DIFFERENT
languages, and you can't just have a SQL statement like this inserted
into VBA code. What's the context? Is this being stored as a Query
using the SQL window, or do you have this as a line in a VBA
procedure?

If the latter, build the SQL string *as a string variable* and execute
it:

Dim strSQL As String
strSQL = "INSERT INTO BOOKING([Blocked Booked], [Teacher's Initials],
"
& "[Booking Date]) VALUES('" _
& forms![SINGLE BOOKING DETAIL]![Blocked Booked] & "', '" _
& forms![SINGLE BOOKING DETAIL]![Teacher's Initials] _
& "', #" & Date() & "#)"

DoCmd.RunSQL strSQL


String values must be delimited by ' or " and dates by #.

A couple of concerns:

- Why do this at all, instead of using a bound form?
- Putting ' in a fieldname or control name is asking for trouble, as
it may - indeed will - be interpreted as a quotemark
 

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

Similar Threads

SQL Insert 1
compile error on SQL 1
library inventory control 5
PLEASE HELP!!! 1
PLEASE HELP!!!!! 1
Access ID 3
Auto-fill Dates 1
Process records from a query 1

Top