Question Forms/Tables (1 Viewer)

Rogue Programme

Registered User.
Local time
Today, 10:39
Joined
Jul 16, 2003
Messages
55
Hi, I have two forms linked to one table. The 2 forms are linked to eachother. I have a button on form 1 that opens form 2. However, if i click to go on form 2 without saving what i've input in form 1 I lose the data.

My question - is there a way I can insert a piece of code in the buttons' on click event procedure to autosave the data in form 1 before it goes over to form 2?

Form 1 = 'frmclaimdetail'
Form 2 = 'frmpmtpack

Here's the code on the button that links the 2 forms together (on click event procedure):

Private Sub cmdopenpmtpack_Click()
On Error GoTo Err_cmdopenpmtpack_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmpmtpack"

stLinkCriteria = "[ClaimID]=" & "'" & Me![ClaimID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
[Forms]![frmpmtpack]![ClaimID].SetFocus


Exit_cmdopenpmtpack_Click:
Exit Sub

Err_cmdopenpmtpack_Click:
MsgBox Err.Description
Resume Exit_cmdopenpmtpack_Click

End Sub

Also, I'm curious as to why i lose the data if it's all being stored in the same table.

Thanks
Mike
 

jzwp22

Access Hobbyist
Local time
Today, 05:39
Joined
Mar 15, 2008
Messages
2,629
The following shown in red should force Access to save the record before moving the focus to the second form.



Code:
Private Sub cmdopenpmtpack_Click()
On Error GoTo Err_cmdopenpmtpack_Click
[COLOR="Red"]DoCmd.RunCommand acCmdSaveRecord[/COLOR]
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmpmtpack"

stLinkCriteria = "[ClaimID]=" & "'" & Me![ClaimID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
[Forms]![frmpmtpack]![ClaimID].SetFocus


Exit_cmdopenpmtpack_Click:
Exit Sub

Err_cmdopenpmtpack_Click:
MsgBox Err.Description
Resume Exit_cmdopenpmtpack_Click

End Sub

As to your question, Access does not save the record until either all controls have been cycled through on the form (and focus moves to the next record) or focus moves to a subform on the form. Out of curiosity, why do you have 2 forms bound to the same table?
 

dcb

Normally Lost
Local time
Today, 11:39
Joined
Sep 15, 2009
Messages
529
Also, I'm curious as to why i lose the data if it's all being stored in the same table.
Because you have not saved the edits the record is in fact locked - this happenes for the entire record not just the field you are trying to update
For example:
If you had a contacts form with Name,Mobile etc and a popup form with address, birthday etc on it assuming the data came from the same table
this would work most of the time as someone may only update one detail at a time (as it gets changed) but if the user tried to update the Mobile(mainForm) and the address(popup) at the same time you would have the same issue - The record has already been locked by the Mobile update that has yet to be saved

Have a look at the Dirty property - this tells you if the record is in "edit mode"
 

Rogue Programme

Registered User.
Local time
Today, 10:39
Joined
Jul 16, 2003
Messages
55
Thanks for your replies.

jzwp22, the reason I had 2 forms was because although the data was stored in the same table; form 2 had data that would not be known until a later date. I would of created another table but because there was only a 1 to 1 relationship i thought I'd go down the 2 forms route. However, in saying all that it was causing me too many problems so I've now reverted back to 1 table and 1 form. So much easier.

Thanks

Mike
 

jzwp22

Access Hobbyist
Local time
Today, 05:39
Joined
Mar 15, 2008
Messages
2,629
I agree, I think the 1 table/form is the better approach. Good luck with your project.
 

Users who are viewing this thread

Top Bottom