Committing Records To Table

G

Guest

Im helping create an Access database to monitor IT stock. The person who
will be using the database wants a button on the form 'Stock_Level_Edit' to
commit new records to a table 'Equipment_Table'. I know this is not best
practice, but this is what the person is looking for. How do I do this?
Just now the data is entered automatically without having to press a button.
 
D

Douglas J. Steele

That's the default behaviour of Access, and getting around it is a nuisance.

You could convert to an unbound form, but that's a lot of work, and does
create limitations on what you can do on a form.

You could create a module-level boolean variable (call it mbooOkayToSave).

In the Click event of the button, set the value of that variable to True,
and save the data:

Private Sub NameOfButton_Click()

If Me.Dirty Then
mbooOkayToSave = True
Me.Dirty = False
End If

End Sub

In the form's BeforeUpdate event, check the value of the variable, and
cancel if it's not True:

Private Sub Form_BeforeUpdate(Cancel As Integer)

Cancel = (mbooOkayToSave = False)

End Sub

In the form's AfterUpdate event, reset the variable:

Private Sub Form_AfterUpdate()

mbooOkayToSave = False

End Sub
 
G

Guest

Ive put in the code you gave me, when i go to save the record i get an error
message coming up:

run time error '2101'
the setting you entered isnt valid for this property

when i click on debug it takes me to the line:

Me.Dirty = False

Is the code you gave me to change the variable value? If not then im not
sure how to do this.

Thanks for the help
 
G

Guest

Should also have said, I'm looking to do the same thing with deleting
records. Can this be done on the same form as the adding records and again
how do you do it? Is it possible to open a blank form? Just now when I open
a form I get the first record in the table its linked to.

thanks for the help

Tommy
 
D

Douglas J. Steele

I don't know what to say. That's valid code!

I did warn you that getting around Access's normal behaviour is a nuisance!
Can you not convince the user that he/she should accept how Access works?
 

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