![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Access 2003 Database FE & BE Problem: *Providing a multi sort capability for unsophisticated users driven by up to three fields. *Only ascending sorts will be provided and the field sort order will be controlled via code. *Access’ intrinsic filter by form will not be used. The data to be sorted displays as a child form. *This form has 3 unbound option buttons that are used to select the desired fields on which to base the sort. *None or any combination of the 3 selections are possible and the order in which the selections are made matter. We will call chkDos the sort select for dt_service, chkDescthe sort select for svc_new, and chkSvcCd the select for svc_new_num. *There is a “Sort” button that is clicked after sorts are selected. *Currently, the code I have sorts the fields in the following order (if selected): *dt_service, svc_new, svc_new_num. *An additional requirement has been imposed stating that the order that the option buttons are selected matters. *For example, clicking the sort option controls in this order svc_new_num, dt_service, & svc_new, would make the sort order the same. *The OrderBy = “svc_new_num, dt_service, svc_new”. *Selecting only svc_new_num and *svc_new would create an OrderBy= “svc_new_num, svc_new”. The existing code: Sub sFilterForm() '================================================= ======================= ' Procedure : sFilterForm ' Purpose * : Logic that drives sorting of form. ' Author * *: Bob ' Phone * * : ' Email: ' DateTime *: 2/5/2010 14:00 ' Notes * * : Sort can be on any combination (and/or) of the following fields: ' dt_service, svc_new, and svc_new_num. Called by Sub btnSort_Click. '------------------------------------------------------------------------ 'Revision History '================================================= ======================= * * Dim bDos * * * * * *As Boolean * * Dim bDesc * * * * * As Boolean * * Dim bSvc * * * * * *As Boolean * * Dim strSort * * * * As String On Error GoTo sFilterForm_Error * * bDos = False * * bDesc = False * * bSvc = False * * With Me * * * * If .chkDos = -1 Then * * * * * * bDos = True * * * * End If * * * * If .chkDesc = -1 Then * * * * * * bDesc = True * * * * End If * * * * If .chkSvcCd = -1 Then * * * * * * bSvc = True * * * * End If * * * * If (bDos = False) And (bDesc = False) And (bSvc = False) Then * * * * * * .OrderByOn = False * * * * * * .lblbtnSort.Caption = "Sort" * * * * * * MsgBox "No sort criteria selected.", vbInformation * * * * * * Exit Sub * * * * End If * * * * If (bDos = False) And (bDesc = False) And (bSvc = False) Then * * * * * * strSort = "~" * * * * ElseIf (bDos = False) And (bDesc = False) And (bSvc = True) Then * * * * * * strSort = "svc_new_num" * * * * ElseIf (bDos = False) And (bDesc = True) And (bSvc = False) Then * * * * * * strSort = "svc_new" * * * * ElseIf (bDos = False) And (bDesc = True) And (bSvc = True) Then * * * * * * strSort = "svc_new, svc_new_num" * * * * ElseIf (bDos = True) And (bDesc = False) And (bSvc = False) Then * * * * * * strSort = "dt_service" * * * * ElseIf (bDos = True) And (bDesc = False) And (bSvc = True) Then * * * * * * strSort = "dt_service, svc_new_num" * * * * ElseIf (bDos = True) And (bDesc = True) And (bSvc =False) Then * * * * * * strSort = "dt_service, svc_new" * * * * ElseIf (bDos = True) And (bDesc = True) And (bSvc =True) Then * * * * * * strSort = "dt_service, svc_new, svc_new_num" * * * * Else * * * * * * strSort = "~" * * * * End If * * * * If strSort = "~" Then * * * * * * .OrderByOn = False * * * * * * .lblbtnSort.Caption = "Sort" * * * * Else * * * * * * .OrderBy = strSort * * * * * * .OrderByOn = True * * * * * * .lblbtnSort.Caption = "Sort= " & strSort * * * * End If * * End With ExitHere: * * Exit Sub sFilterForm_Error: * * MsgBox "Error " & Err.Number & " (" & Err.Description & ") " _ * * & "in procedure sFilterForm of VBA Document Form_sfrmClaimGen" End Sub The existing form has limited real-estate. *I was considering hiding a text box control to store field sort (and resetting/ordering as required) information or a popup dialog box, but I’m unsure how to implement either. *I would appreciate advice on how to proceed with a solution based on the requirements and user limitations. Regards, Bob |
#3
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |