Results 1 to 3 of 3

Thread: add New record

  1. #1
    Join Date
    Dec 2003
    Location
    Toronto
    Posts
    11

    Question Unanswered: add New record

    I'm using a form to add a new record to a table. the table has a autonumber as PK. I have a button that when clicked validate the entry from form fields to table fields. The problem is it would accept to add the new record the first time, I have to click a second time to make it go through. And this because the autonumber had to jump to a new number first.
    Can please tell if there is a way to achieve that without having to click twice( just to let you know I'm using this code in the button Sub:
    If Not Me.NewRecord Then
    RunCommand acCmdRecordsGoToNew
    End If

    On Error GoTo ErrNew
    DoCmd.RunCommand acCmdRecordsGoToNew
    Exit Sub
    ErrNew:
    Select Case Err
    Case 2046
    'Command not available
    MsgBox "You cannot add a record at this time.", vbInformation, "Not Available"
    Case Else
    MsgBox Err.Number & ":-" & vbCrLf & Err.Description
    End Select

    so the first click always dispalys "You cannot add a record at this time.", message.

    Another thing as long the form is open I can perform the adding with no problem(only on click on the button) the problem happens only the first time I open the form

    thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    I don't know why you have it going to a new record twice. That could be your error. I use the following:

    If DoubleCheck = -1 Then 'subroutine that checks for nulls
    If Me.Dirty Then DoCmd.RunCommand acCmdSaveRecord
    If SaveInfo <> "" Then
    If Me.DataEntry = 0 Then Me.DataEntry = -1
    DoCmd.GoToRecord , , acNewRec
    End If
    End If

  3. #3
    Join Date
    Dec 2003
    Posts
    16
    I don't know which version of Access you are using (97 for me), but I use this. I am assuming you are using a bound form. This will add the record and make it current.

    'do your checking
    ' open a recordset based on your table or query

    With rst
    .AddNew
    ' write your data
    .Update
    Move 0, .LastModified
    Me.Bookmark=.Bookmark
    End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •