Private Sub Report_Open(Cancel As Integer)
Dim szOrderBy As String
Dim f As Form_frmMyUserChoiceForm
If bIsLoaded("frmMyUserChoiceForm") Then
'Only do this if the frmMyUserChoiceForm is loaded
'otherwise don't change the sort order set at report design time.
Set f = Forms!frmMyUserChoiceForm
Select Case f.FraOrderBy.Value
Case 1 ' Surname, Name
szOrderBy = "[NameLast], [NameFirst]"
Case 2 ' Staff Number
szOrderBy = "[StaffNbr]"
End Select
Me.OrderBy = szOrderBy
Me.OrderByOn = True
Set f = Nothing
End If
End Sub
Function bIsLoaded(szFrmName As String) As Boolean
' Determines if a form is loaded.
Const conFormDesign = 0
Dim n As Integer
bIsLoaded = False
For n = 0 To Forms.Count - 1
If Forms(n).FormName = szFrmName Then
If Forms(n).CurrentView <> conFormDesign Then
bIsLoaded = True
Exit Function ' Quit function once form has been found.
End If
End If
Next
End Function