2

I want a new entry created in table Moments using the predefined defaults for each field.

I've tried the following lines and I'm getting a syntax error for both. What would be the correct method to do this in Access?

INSERT INTO Moments VALUES ()

Access highlights the end bracket after clicking ok on syntax error. 

and

INSERT INTO Moments () VALUES ()

Access highlights the first bracket after clicking ok on syntax error. 

and

INSERT INTO Moments default values

Access highlights default after clicking ok on syntax error. 
2
  • Does it have to be a query? You can easily do this using VBA. Commented Jun 21, 2018 at 14:29
  • No it does not have to be a query. How would you go about doing it in VBA. Commented Jun 21, 2018 at 14:30

1 Answer 1

2

In VBA, this can easily be achieved with recordsets:

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("Moments") 'Open table
rs.AddNew 'Add row
rs.Update 'Commit to table
Sign up to request clarification or add additional context in comments.

3 Comments

How would you get the id of the record newly created?
That's a different question. See this answer. Alternatively, you can use rs.MoveLast and then rs!ID (if ID is your id column)
rs.Bookmark = rs.LastModified -- msdn.microsoft.com/en-us/library/office/ff195859.aspx @Tolure

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.