Full Version: Sort toggle and Zoom buttons?
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
StephKai
Hi, wonderful UA folks--
would like to add two buttons to help my user manage the results of a search:
1) a button to toggle between A-Z and Z-A sorting on the column in which they have clicked. (If toggling isn't possible, I'm willing to add two separate buttons for ascending and descending sort.)
2) a button to ZOOM into the cell they have clicked. (To view the full contents of a long cell without resizing the column.)
Oknow 1) can be done with the toolbar buttons and through the right-click menu, and 2) can be done with SHIFT-F2. However, my user is not comfortable with databases, and if possible, these buttons would make my form a lot easier for her to use.
I'm attaching the database, please let me know if I've done so incorrectly.
Thanks very much,
--Steph
StephKai
I'm sorry, I should have mentioned that I would like to put the buttons on the form frm_main.
ace
I use DoCmd.RunCommand acCmdZoomBox in the
double click event of the textbox I want to zoom.
oing the same from a command button on another form
makes things a bit more involved.
Same goes for your sorting requirements.
DoCmd.RunCommand acCmdSortAscending will sort the column
that has the focus. Doing the same from a command button
on another form would be a bit more involved.
StephKai
Hi Ace--
Thanks for your help! I like the double-click event for zooming, that works nicely.
Hmm, yeah, when I try to put DoCmd.RunCommand acCmdSortAscending in the Event Procedure of a button on my main form, I get the error "The command or action 'SortAscending' isn't available now." when I click it.
Can I say something like:
DoCmd.RunCommand acCmdSortAscending Me.sbf_preorder ?
I'm at the 'struggling to learn VBA' stage, so I don't know the correct syntax...
--Steph
ace
I have never actually implemented sorting in this particular way
before so this seems to work , but is not very well tested.
!--c1-->
CODE
[color="blue"]
Private Sub cmd_preorder_sorttoggle_Click()
  
  Me.sbf_preorder.SetFocus
  Me.sbf_preorder.Form.Controls(Me.sbf_preorder.Form.ActiveControl.Name).SetFocus
  
  With Me.cmd_preorder_sorttoggle
    If .Caption = "Sort Ascending" Then
      DoCmd.RunCommand acCmdSortAscending
      .Caption = "Sort Descending"
    Else
      DoCmd.RunCommand acCmdSortDescending
      .Caption = "Sort Ascending"
    End If
  End With
End Sub[/color]
StephKai
Hi Ace--
ow...that works perfectly! Very cool code, thanks so much.
--Steph
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.