Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a Subform Table

Status
Not open for further replies.

alblunkproex

IS-IT--Management
Jun 25, 2008
18
US
Hi, basically I have a couple tables in subforms that track parts that have been ordered under the main order number. What I basically need to have happen is automate the ability to right click the column heading and sort ascending. Anyway to do this through vba?
 
You should be able to use the click event of the label. For example:

Code:
Private Sub Level_Label_Click()
Me.OrderBy = "Level"
Me.OrderByOn = True
End Sub
 
ya but can I get a control on the main form to activate it to automatically sort?
 
Too easy mate, I use this lots:

Create an onclick event for the caption and colour it blue and underline it so the user (if they have windws default hyperlink colour) will have attention drawn to it.

The event should have this code:

Code:
    Call SortBy("field1", Me)

which is calling a sub that can be declared form level as:

Code:
Sub SortBy(strSource As String, frm As Form)
    frm.OrderByOn = True
    If frm.OrderBy = strSource Then
        frm.OrderBy = strSource & " DESC"
    Else
        frm.OrderBy = strSource
    End If
End Sub

It's dead simple but makes for a nice user interface. it also works of course with more complex calls cos of the simple nature of the method. And naturally you can tell from the code, if a form is aready sorted by the clicked field it re-sorts in opposite direction like most MS sort feaatures a user will be used to.

Hope this helps fella, happy dayz

JB
 
seems like it would work, but basically i just want the subform to be sorted after I close a parts order/edit form.. anyway I can do that?
 
How are ya alblunkproex . . .
alblunkproex said:
[blue] . . . i just want the subform to be sorted after I close a parts order/edit form . . .[/blue]
The quote above should've been your post origination!

Base the recordsource of the subform on a query that includes your sorting and [blue]requery the subform[/blue].

In the close event of your order/edit form, try:
Code:
[blue]   Forms![purple][B][I]MainFormName[/I][/B][/purple]![purple][B][I]subFormName[/I][/B][/purple].Form.Requery[/blue]
[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
thanks, i didnt want it to come to a query. But it is the easiest way. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top