how do I add new record?

M

Marc

I am trying to create the code for a button on a form that adds a new record
in a table and then sets the data values in the new record fields.

How do I do this??? Its driving me mad

on my form is:
supposing a list box called 'chooselist1' - values are looked up from
another table
and a date box called 'enterdate' - user enters date

I want to be able to select an option from the list box, enter the date,
then click on this button that will add a new record to table 'table1' - the
fields in this new record will be the values from 'chooselist1' and
'enterdate'

can anyone help???
 
G

Graham Mandeno

Hi Marc

You can execute a SQL "INSERT" statement:

Dim db as DAO.Database
Dim sSQL as string
sSQL = "Insert into table1 ([NameOfOptionField], " _
& "[NameOfDateField]) values (" _
& chooselist1 _
& "," & Format(enterdate, "\#mm/dd/yyyy\#") & ");"
Set db = CurrentDb
db.Execute sSQL, dbFailOnError
Set db = Nothing

If the option field is text, not numeric, then the chooselist1 value must be
enclosed in quotes:

& "'" & chooselist1 & "'" _

I suggest you look up the various bits of syntax I've used in the online
help to get a good understanding of exactly what the code is doing.
 

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