Reputation: 10485
My function:
Public Function openRpt(strReportName As String, form as ??, subform as ??)
On Error Resume Next
If (Forms![form]![subform].Form.lock = False) Then
DoCmd.RunCommand acCmdSaveRecord
End If
DoCmd.OpenReport strReportName, acViewPreview, "", _
"[num]=Forms![form]![subform].Form.[num]"
End Function
What it does is to save a record from subform
if it isn't locked, and then launch a report. I want to switch from
and subform
with matching variables that will point at the right forms, and will be given as arguments.
Upvotes: 0
Views: 126
Reputation: 15923
for (1):
First, it may be tempting to call variables form and subform, but watch out for possible errors if names you use match or are close to reserved names.
Also, lock is not a valid property of a form or subform. If you are trying to test if a form has been changed, you would test .Dirty
This is how I would code your function:
Option Explicit
Public Function openRpt(strReportName As String, frm as String, sFrm as string)
If (Forms(frm).Form(sFrm).Form.Dirty = True) Then
DoCmd.RunCommand acCmdSaveRecord
End If
DoCmd.OpenReport strReportName, acViewPreview, "", _
"[num]=Forms(""" & frm & """).Forms(""" & sFrm & """).Form.[num]"
End Function
for (2): from the Microsoft Blog
Upvotes: 2