Thanks. This works fine. I considered SQL but am such a novice that I didn't even know about the currentDb object. I had been trying to do the SQL directly from VBA code modules. Thanks again.
--- In ms_access@yahoogroups.com, Lonnie Johnson <[EMAIL PROTECTED]> wrote: > > You could use an append query in your code. > > CurrentDb.Execute "INSERT INTO CUSTOMERS ( LASTNAME, FIRSTNAME ) " _ > & "VALUES( 'JOHN', 'SMITH')" > > As far as the auto increment, if you set your sequence field's data type to AutoNumber in the table, then it will automatically increase when you add a new record with the above code. > > > > May God bless you beyond your imagination! > Lonnie Johnson > ProDev, Professional Development of MS Access Databases > Visit me at ==> http://www.prodev.us > > > > > > > > > ----- Original Message ---- > From: bryan.leggo <[EMAIL PROTECTED]> > To: ms_access@yahoogroups.com > Sent: Tuesday, November 20, 2007 3:53:04 PM > Subject: [ms_access] Created a new record, now how do I programmatically save the data? > > I would like the user to be able to click on a "New Record" button > and have it put a new record in the table with a few predefined > fields including the important one called "Sequence" which is a > simple incremental integer. The table is called "Donations". Here's > part of my code: > > Private Sub cmdAddRecord_ Click() > On Error GoTo Err_cmdAddRecord_ Click > Dim nNextRec As Integer > DoCmd.GoToRecord , , acNewRec > nNextRec = ListBrowser. ListCount + 1 > lblRow.Caption = Str(nNextRec) > > ' Here's the missing part. How do I assign values to > ' a few of the fields/columns in the new record including > ' the Sequence field and then how do I ensure that the > ' entire record is saved to the table before I go to > ' the next step and call the main editing form just below. > ' I'm not even sure how to do the basic assignments. > ' Is it dome with Form!ListBrowser. fieldname = value or > ' do I reference the main table somehow? Donations.Sequence > ' doesn't work. I know this is basic stuff but I'm stuck. > > Call cmdEditDonations_ Click ' Detailed data entry form > > Exit_cmdAddRecord_ Click: > Exit Sub > Err_cmdAddRecord_ Click: > MsgBox Err.Description > Resume Exit_cmdAddRecord_ Click > End Sub > > > > > > ______________________________________________________________________ ______________ > Get easy, one-click access to your favorites. > Make Yahoo! your homepage. > http://www.yahoo.com/r/hs > > [Non-text portions of this message have been removed] >