My report rptOrderConf has a button to bring up a shortcut menu that allows me to choose what I want the report sorted by.
Code:
Sub SortPopupMenu(x, y)
'Menu on Order Confirmation Report to change order of details.
Dim SortMenu As CommandBar
Dim SortBy As CommandBarControl
Set SortMenu = CommandBars.Add("", msoBarPopup, , True)
Set SortBy = SortMenu.Controls.Add: SortBy.Caption = "Product Type": SortBy.OnAction = "SortByProduct"
Set SortBy = SortMenu.Controls.Add: SortBy.Caption = "Strain Name": SortBy.OnAction = "SortByStrain"
Set SortBy = SortMenu.Controls.Add: SortBy.Caption = "Order Entered": SortBy.OnAction = "SortByItem"
Set SortBy = SortMenu.Controls.Add: SortBy.Caption = "Custom Sort": SortBy.OnAction = "SortByCustom"
SortMenu.ShowPopup x, y
End Sub
Sub SortByProduct()
Screen.ActiveReport.OrderBy = "[ProdType]"
Screen.ActiveReport.OrderByOn = True
End Sub
Sub SortByStrain()
Screen.ActiveReport.OrderBy = "[StrainName]"
Screen.ActiveReport.OrderByOn = True
End Sub
Sub SortByItem()
Screen.ActiveReport.OrderBy = "[InfoID]"
Screen.ActiveReport.OrderByOn = True
End Sub
Sub SortByCustom()
Screen.ActiveReport.OrderBy = "[SortOrder]"
Screen.ActiveReport.OrderByOn = True
End Sub
This used to work great, but I have changed the database a bit since I put this in place, and don't use this button very often so I don't know when it quit working.
The report is based on a query with a field ConfTableID. This field uses function GetConfID() as the criteria.
Code:
Public Function GetConfID() As Integer
If CurrentProject.AllForms("frmOrderConf").IsLoaded = True Then
GetConfID = Forms!frmOrderConf!ConfTableID
ElseIf CurrentProject.AllForms("frmOrderList").IsLoaded = True Then
GetConfID = Forms!frmOrderList!ConfTableID
ElseIf CurrentProject.AllReports("rptOrderConf").IsLoaded = True Then
GetConfID = Reports!rptOrderConf!ConfTableID
ElseIf CurrentProject.AllReports("rptOrderConfSample").IsLoaded = True Then
GetConfID = Reports!rptOrderConfSample!ConfTableID
Else
MsgBox "I can't tell what Order you are trying to open. Please go back and try again."
End If
End Function
When I try to use any of the sort-by buttons, I get error 2427: "You entered an expression that has no value."
If I debug, a line from GetConfID() is highlighted: GetConfID = Reports!rptOrderConf!ConfTableID
I am wondering if the report/query has to reload to change the sort order, meaning nothing is technically open to get the correct criteria..? Although I get the error and no records have changed.
Any help would be really appreciated!
Thanks