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!

MS Access, Date asc/desc Toggle button in VBA, need help 2

Status
Not open for further replies.

mesafloyd

Technical User
Aug 19, 2006
31
US
Using MS Access, continuous Form, 200 to 600+ records.

I have made a button(SortByDate)
I have made a field(LastUpdate)
This field primarily holds dates, but may be blank or short text(User may enter a note to themselves)

I'm trying to make the button to be a 'toggle' button to sort the records by this LASTUPDATE field.
Press once, is Ascending
Press again, is Descending
or visa versa - Does not matter to ascend or descend first, just toggle.
Name on the button does not need to change nor show Icon for up/down (do not need fancy stuff really)

I am not good at programming(Hardware guy) but I do have some very basic ability.

Any thoughts or suggestion that would push me in the right direction.. maybe the command to use?? .. Is this a 'Filter' command or is there a 'Sort' command in VB code? Suggested code would be wonderful.
I think this should be simple but I am not very good here.
Most of my form is working, I am stuck here.

If making a 'toggle' is too code laborous, I would be fine with a SORT from earliest date on top to readily access old records.
Any help would be appreciated
 
For ease of coding, can't you have two buttons, Ascending and Descending? Then place the following code on the appropriate button:

Private Sub Command2_Click()
Form.OrderBy = "LastUpdate ASC"
Form.OrderByOn = True
End Sub

Private Sub Command3_Click()
Form.OrderBy = "LastUpdate Desc"
Form.OrderByOn = True
End Sub
 
fneily,
Thank you so much for the help and taking the time to help.
Both routines work perfectly.
Excellant solution to my problem
Kindest Regards,
 
Hello All

I blue Bird flew in on another forum and posted this code.
It does exactly as I wanted....
Single button Toggle .. ascend... descend

Private Sub SORTBYDATE_Click()
If Me.OrderBy = "LastUpdate" Then
Me.OrderBy = "LastUpdate desc"
Else
Me.OrderBy = "LastUpdate"
End If
Me.OrderByOn = True
End Sub

thanks to all.
MesaFloyd

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top