Dec 10, 2001 #1 kwill Technical User Aug 15, 2001 49 US I'm trying to make a sort button on my form. Anyone know what the VBA is? thanks, mucho
Dec 11, 2001 #2 paulbasel Programmer Nov 21, 2001 10 CH I use the following function in a form module: Public Sub ChangeSortOrder(frm As Form, strFld As String) On Error GoTo ErrHand If frm.OrderBy = strFld Then frm.OrderBy = strFld & " DESC" Else frm.OrderBy = strFld End If frm.OrderByOn = True ExitProc: Exit Sub ErrHand: MsgBox Err.Number & " " & Err.Description GoTo ExitProc End Sub Then simply call the function from an on-click procedure of your button like the following: Call ChangeSortOrder(Me, "MyButton" There are other ways but I like to use a function if I have a number of buttons, such as column sorting on a continuous form layout. Paul Upvote 0 Downvote
I use the following function in a form module: Public Sub ChangeSortOrder(frm As Form, strFld As String) On Error GoTo ErrHand If frm.OrderBy = strFld Then frm.OrderBy = strFld & " DESC" Else frm.OrderBy = strFld End If frm.OrderByOn = True ExitProc: Exit Sub ErrHand: MsgBox Err.Number & " " & Err.Description GoTo ExitProc End Sub Then simply call the function from an on-click procedure of your button like the following: Call ChangeSortOrder(Me, "MyButton" There are other ways but I like to use a function if I have a number of buttons, such as column sorting on a continuous form layout. Paul
Dec 11, 2001 #3 paulbasel Programmer Nov 21, 2001 10 CH kwill Sorry, I hit the submit button too fast. The strFld has to be the underlying field that the button is to sort. Call ChangeSortOrder(Me, "MyFieldName" Paul Upvote 0 Downvote
kwill Sorry, I hit the submit button too fast. The strFld has to be the underlying field that the button is to sort. Call ChangeSortOrder(Me, "MyFieldName" Paul