how can I create a record in VBA?

G

Guest

I'm new in programming in VBA.
I've created a form in which the items sold should be filled in. I The items
sold should update the inventory table. It should deduct the quantity from
the quantity on hand.

How do I do that with VBA?
 
G

Guest

To create a new record in VBA code you could use something like this:
MyForm.Recordset.AddNew
To update the record you should use
MyForm.Recordset.Update
 
J

Josh Nankivel via AccessMonster.com

Here's an example.

Private Sub cmdSubmit_Click()
Dim rst As DAO.Recordset
Dim mdbLocal As DAO.Database

On Error GoTo Err_cmdSubmit_Click

Set mdbLocal = DBEngine(0)(0)
''' Specify table name for recordset
Set rst = mdbLocal.OpenRecordset("tblName", dbOpenDynaset,
dbAppendOnly)
rst.AddNew

With rst

''' Example if you have some data in a control in a subform:
!tblField1 = Forms!frmName.Field1
''' Example if control is in the main form
!tblField2 = Me!Field2

End With

rst.Update
rst.Close
Set mdbLocal = Nothing

Forms!frmName.Field1 = Null
Me!Field2 = Null

Exit_cmdSubmit_Click:
Exit Sub

Err_cmdSubmit_Click:
Resume Exit_cmdSubmit_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top