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. 
Erik A
  • 31,639
  • 12
  • 42
  • 67
Tolure
  • 859
  • 1
  • 14
  • 34

1 Answers1

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
Erik A
  • 31,639
  • 12
  • 42
  • 67
  • How would you get the id of the record newly created? – Tolure Jun 21 '18 at 14:33
  • That's a different question. See [this answer](https://stackoverflow.com/a/17931268/7296893). Alternatively, you can use `rs.MoveLast` and then `rs!ID` (if `ID` is your id column) – Erik A Jun 21 '18 at 14:37
  • 1
    `rs.Bookmark = rs.LastModified` -- https://msdn.microsoft.com/en-us/library/office/ff195859.aspx @Tolure – Andre Jun 21 '18 at 14:43