Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2006
    Posts
    40

    Unanswered: VBA AddRecord command issue

    Hi guys,

    i tried using the AddRecord command provided by Acess but the new record is not been appended to the table but instead it has been overwritten. I have set the focus for the field under the acNewrc already. By right i shld be able to append the record at the end of the record of the field and nt overwritting the record.

    primary key
    SerialCode (Autokey)

    Fields
    StudentId, subjectcode, course, grade

    Combo box
    StudentId (predefined list) - S1, S2, S3, S4, S4, S5

    AddRecord command (by Acess under operation)
    acNewRc
    StudentId.SetFocus
    subjectCode.SetFocus
    course.SetFocus
    grade.SetFocus

    Tks for your assistance.

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    Could you post the code you are using now?
    Me.Geek = True

  3. #3
    Join Date
    May 2005
    Posts
    1,191
    Is this a repost of this thread?
    Me.Geek = True

  4. #4
    Join Date
    Nov 2006
    Posts
    40

    AddRecord issue - Urgent help request!

    Hi Nick & guys,
    Here is the code
    ps assist on this. Million tks!

    Private Sub AddRecord_Click()
    On Error GoTo AddRecord_Click

    DoCmd.OpenForm "Record"
    DoCmd.GoToRecord, "Record", acNewRec
    Combo1.SetFocus ' predefined list (s1,s2,s3,s4,s5)
    StudentId 'textbox bound to controlSource StudentId
    course.SetFocus 'textbox 'textbox bound to controlsource coursecode
    SubjectCode.SetFocus 'textbox
    Grade.SetFocus 'textbox

    Exit_AddRecord_Click:
    Exit Sub

    Err_AddRecord_Click:
    MsgBox Err.Description
    Resume Exit_AddRecord_Click

    End Sub

    Private Sub Combo1_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[SerialCode] = " & Str(Nz(Me![Combo1], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub

  5. #5
    Join Date
    Jan 2007
    Posts
    5
    Why dont you use Recordsets for adding new data?

    Code:
    Sub Whaterver()
    
    Dim rst As DAO.Recordset
    Set rst = CurrentDb.OpenRecordset("yourTable")
    
    rst.AddNew
    
    rst!FieldName = YourInput
    rst!etc.............
    
    rst.Update
    
    rst.Close
    
    Set rst = Nothing
    
    End Sub

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I'm confused:
    Code:
    DoCmd.OpenForm "Record"
    DoCmd.GoToRecord, "Record", acNewRec
    Combo1.SetFocus ' predefined list (s1,s2,s3,s4,s5)
    StudentId 'textbox bound to controlSource StudentId
    course.SetFocus 'textbox 'textbox bound to controlsource coursecode
    SubjectCode.SetFocus 'textbox
    Grade.SetFocus 'textbox
    You open a form, you go to a new record, and then you set focus to each control in turn. How do you expect this to add new data?
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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