G
Guest
My goal is to change the RecordSource of a report depending on which form
accesses it. My attempted strategy was to use a function (frmLoaded) to
determine whether one of the forms was open, and call that function in the
subroutine of the OnOpen arguments for the report. (I don't particularly
like this strategy, since it only allows for two options for the
RecordSource: frmLoaded True and frmLoaded False.)
The code defaults to the second option no matter which form accesses the
report.(The form is not open, "frmLoaded(ByVal MyForm) <> True "). I have
tried "= True" and "= False" instead of "= True" and "<> True", and I have
tried "= -1" and "= 0") with the exact same results. I have also tried
embedding the function within the sub, but I triggered the Compile Error:
"Expected End Sub."
I am new to calling functions (and writing them for that matter), so I have
a sneaking suspicion that my entire code may be just a fantasy.
Function frmLoaded(ByVal MyForm As String) As Integer
If SysCmd(acSysCmdGetObjectState, acForm, MyForm) <> 0 Then
If Forms(MyForm).CurrentView <> 0 Then
frmLoaded = True
End If
End If
End Function
Private Sub Report_Open(Cancel As Integer)
Dim MySQL As String
Dim MyForm As String
MyForm = "Forms!frmTransmittals"
If frmLoaded(ByVal MyForm) = True Then
MySQL = "SELECT * FROM tblYouGuysAreGreat"
ElseIf frmLoaded(ByVal MyForm) <> True Then
MySQL = "SELECT * FROM qryWhatsWrongWithMe"
End If
Me.RecordSource = MySQL
End Sub
accesses it. My attempted strategy was to use a function (frmLoaded) to
determine whether one of the forms was open, and call that function in the
subroutine of the OnOpen arguments for the report. (I don't particularly
like this strategy, since it only allows for two options for the
RecordSource: frmLoaded True and frmLoaded False.)
The code defaults to the second option no matter which form accesses the
report.(The form is not open, "frmLoaded(ByVal MyForm) <> True "). I have
tried "= True" and "= False" instead of "= True" and "<> True", and I have
tried "= -1" and "= 0") with the exact same results. I have also tried
embedding the function within the sub, but I triggered the Compile Error:
"Expected End Sub."
I am new to calling functions (and writing them for that matter), so I have
a sneaking suspicion that my entire code may be just a fantasy.
Function frmLoaded(ByVal MyForm As String) As Integer
If SysCmd(acSysCmdGetObjectState, acForm, MyForm) <> 0 Then
If Forms(MyForm).CurrentView <> 0 Then
frmLoaded = True
End If
End If
End Function
Private Sub Report_Open(Cancel As Integer)
Dim MySQL As String
Dim MyForm As String
MyForm = "Forms!frmTransmittals"
If frmLoaded(ByVal MyForm) = True Then
MySQL = "SELECT * FROM tblYouGuysAreGreat"
ElseIf frmLoaded(ByVal MyForm) <> True Then
MySQL = "SELECT * FROM qryWhatsWrongWithMe"
End If
Me.RecordSource = MySQL
End Sub