Save form before entering a linked form

Mark-BES

Registered User.
Local time
Today, 14:45
Joined
Nov 23, 2004
Messages
85
This is the code that runs when a button on form 1 is pressed to open form 2(form 2 is called Replacement Unit):

Private Sub Command80_Click()
On Error GoTo Err_Command80_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Replacement Unit"

stLinkCriteria = "[Repair No]=" & Me![REPAIR No]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command80_Click:
Exit Sub

Err_Command80_Click:
MsgBox Err.Description
Resume Exit_Command80_Click

End Sub

I want to save the changes to [form 1] before [Replacement Unit] opens. What and where do I enter code? Sorry, only just started to learn VB. (Using Acc97). Any help would be great! :)
 
Save

Try this:

Private Sub Command80_Click()
On Error GoTo Err_Command80_Click

DoCmd.RunCommand acCmdSaveRecord

rest of your code..


Two remarks here:
It is good practice to use meaningful names in the code,
so instead of 'Command80' something like: 'OpenFormReplacement Unit'.
It helps when you have to modify or debug the code, it will be easier
to identify.

Second, don't use spaces in table- and fieldnames, it may cause
problems at some point. Instead of 'Repair No' use 'RepairNo' or
Repair_No'.

Good luck.
 
Thank you!

Thats great! thank you!

Your points regarding my coding practice is welcomed. I am learning (slowly)

Thanks again. :)
 

Users who are viewing this thread

Back
Top Bottom