Instantaneous record commitement

  • Thread starter Thread starter George Papadopoulos
  • Start date Start date
G

George Papadopoulos

Hello everybody

I`ve built a form with controls on it bounded to a table in my database. I
also have this button on the form, which pops up a new independent form. I
would like to have the current record i my first form commited to the
database, before the second form pops up. How can I do this using VBA?

thx, in advance

George Papadopoulos
 
In the sub for opening you second form use

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

HTH,

Neil.
 
I added the code you gave to the Open Sub of my second form. When I enter
a record in the second form and try to close it, I still get the error
message.
The problem is that the second form refers to the record just entered in
the first form, from which it was opened. That record has not been commited
to the database, so when Access tries to write the record in the second form
it fails.
What am I doing wrong?
 
Sorry George,

My explanition was a bit vague. Place the code in the first forms command
button click event.

Private Sub MyButton_Click()

' Save the record in the first form if changes have been made
If Me.Dirty Then
Me.Dirty = False
End If
' Open the second form
DoCmd.OpenForm "frmSecondForm"

End Sub

'Me' in the code above is like a shortcut to the form that the code is in.
For e.g., If the above code is in the first form code module, you can use Me
instead of writing Forms!frmFirstForm.... What the code is doing is checking
to see if any changes have been made to the first form (checking it's dirty
property) if it is True, then save the changes to the record (set this
property back to false). You could still keep the code in the second forms
load event, but you would have to change Me to be Forms!YourFirstFormsName
in the code. However, doing this would also mean that you would have to
check to see if the first form was actually open before trying to save the
changes in it (Access 2000 and above, the code would be be If
CurrentProject.AllForms("FirstFormName").IsLoaded Then the form is open).

HTH,

Neil.
 
Back
Top