How to add new record to Sub Form in MS Access using VBA

microsoft access tutorial

Currently I am building a new Access database system which operates many forms and sub forms. I have a button which control a sub form. The following code will let a button to add new record to sub form using Visual Basic Application.

DoCmd.GoToRecord

Example:

[codesyntax lang=”vbnet”]

Private Sub cmdCollar_Click()
If selectedprospect = "" Then
MsgBox ("Please select prospect and drillhole first")
Else
If MsgBox("Add new Collar entry?", vbYesNo) = vbYes Then
Me.Tbl_DHCollar_subform.Enabled = True
Me.Tbl_DHCollar_subform.SetFocus
'Code to add new record to subform
     DoCmd.GoToRecord , , acNewRec
Else
End If
End If
End Sub

[/codesyntax]

Admin

Leave a Reply

Your email address will not be published. Required fields are marked *