View Full Version : Save and Open form


crhodus
04-04-2001, 02:31 PM
I want to have the data in Form 1 automatically saved whenever someone click on a button to open Form 2. The button is located on Form 1.

Can I simply copy the code from an auto-generated save button into the code of my auto-generated open button?

I'm not sure of the correct snytax. I haven't dealt with VBA very much.

Here is the syntax from the two buttons that I am refering to.

----------------------------------------
Private Sub SaveCompanyRecord_Click()
On Error GoTo Err_SaveCompanyRecord_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_SaveCompanyRecord_Click:
Exit Sub

Err_SaveCompanyRecord_Click:
MsgBox Err.Description
Resume Exit_SaveCompanyRecord_Click

End Sub
----------------------------------------
Private Sub Open__Project_Click()


On Error GoTo Err_Open__Project_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Project_Form"

stLinkCriteria = "[company_id]=" & "'" & Me![comp_id] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open__Project_Click:
Exit Sub

Err_Open__Project_Click:
MsgBox Err.Description
Resume Exit_Open__Project_Click

End Sub
--------------------------------------
If anyone can help, then thanks!

Rich
04-04-2001, 02:42 PM
One button will do
Private Sub Open__Project_Click()


On Error GoTo Err_Open__Project_Click
Me.Refresh

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Project_Form"

stLinkCriteria = "[company_id]=" & "'" & Me![comp_id] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Open__Project_Click:
Exit Sub

Err_Open__Project_Click:
MsgBox Err.Description
Resume Exit_Open__Project_Click

End Sub

HTH

crhodus
04-05-2001, 07:01 AM
Thanks for you help!
That did the trick.