Saving data in Access table with VB ?

  • Thread starter Thread starter Bauhaus
  • Start date Start date
B

Bauhaus

I have a form with a button and if you click the button, a list of invoices
are generated and saved in the table 'Invoice'.
Problem is, the data isnt saved :(

Here's my code:

Private Sub Knop0_Click()

Dim Invoicenr As Long
Dim Invoicedate As Date

stdocname = "Invoice"
DoCmd.OpenTable stdocname, acViewNormal, acAd

Invoicenr = 111111
Invoicedate = Now

DoCmd.Save acTable, stdocname

End Sub

What am I doing wrong ?
 
DoCmd.Save acTable, stdocname
Is used to save changes to the table object itself, not the data within the
table. Try:

DoCmd.RunCommand acCmdSaveRecord

HTH,
 
I have a form with a button and if you click the button, a list of invoices
are generated and saved in the table 'Invoice'.
Problem is, the data isnt saved :(

Here's my code:

Private Sub Knop0_Click()

Dim Invoicenr As Long
Dim Invoicedate As Date

stdocname = "Invoice"
DoCmd.OpenTable stdocname, acViewNormal, acAd

Invoicenr = 111111
Invoicedate = Now

If Me.Dirty Then Me.Dirty = False
DoCmd.Save acTable, stdocname

End Sub

What am I doing wrong ?

You can use The Docmd method, but the preferred method is to set the Dirty property to False, which forces Access to
save pending changes.

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 

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

Back
Top