By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,561 Members | 3,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,561 IT Pros & Developers. It's quick & easy.

ClickEvent Function Problem

P: n/a
I found the following code which allows me to sort on the click event
of a labelbutton.

The problem occurs when I try to call the function directly from the
ClickEvent, instead of having the ClickEvent run its subroutine.
Any Ideas??

'THIS DOES NOT WORK:
= SortForm([Me],"CRNAME")
'The error is:
'The object doesn't contain the Automation object 'ME.'.

'THIS WORKS:
Private Sub lblSort1_Click()
Call SortForm(Me, "CRNAME")
End Sub

' this code is in Module1
Public Function SortForm(frm As Form, ByVal sOrderBy As String)
'Purpose: Set a form's OrderBy to the string. Reverse if already set.
'Return: True if success.
'Usage: Command button above a column in a continuous form:
' Call SortForm(Me, "MyField")
If Len(sOrderBy) 0 Then
' Reverse the order if already sorted this way.
If frm.OrderByOn And (frm.OrderBy = sOrderBy) Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function

Thanks

Feb 27 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Feb 27, 12:08 pm, "ApexD...@gmail.com" <ApexD...@gmail.comwrote:
I found the following code which allows me to sort on the click event
of a labelbutton.

The problem occurs when I try to call the function directly from the
ClickEvent, instead of having the ClickEvent run its subroutine.
Any Ideas??

'THIS DOES NOT WORK:
= SortForm([Me],"CRNAME")
'The error is:
'The object doesn't contain the Automation object 'ME.'.

'THIS WORKS:
Private Sub lblSort1_Click()
Call SortForm(Me, "CRNAME")
End Sub

' this code is in Module1
Public Function SortForm(frm As Form, ByVal sOrderBy As String)
'Purpose: Set a form's OrderBy to the string. Reverse if already set.
'Return: True if success.
'Usage: Command button above a column in a continuous form:
' Call SortForm(Me, "MyField")
If Len(sOrderBy) 0 Then
' Reverse the order if already sorted this way.
If frm.OrderByOn And (frm.OrderBy = sOrderBy) Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
End If
End Function

Thanks
Me is a keyword only availbe in VB. It does not exist outside a code
module.
If you need the function directly in the event property box, you'll
likely have to refer to the form explicitly.
= SortForm(Forms!FormName,"CRNAME")

I think it's better to leave it in the event proceedure anyway.

Feb 27 '07 #2

P: n/a
ThanksMike
>I think it's better to leave it in the event proceedure anyway.
Since I will use this for quite a few fields, I thought it best to
avoid cluttering my existing code with all the extra procedures.

= SortForm(Forms!FormName,"CRNAME")
This worked great!

ThanksAgain
Greg

Feb 27 '07 #3

P: n/a
Ap******@gmail.com wrote:
>I found the following code which allows me to sort on the click event
of a labelbutton.

The problem occurs when I try to call the function directly from the
ClickEvent, instead of having the ClickEvent run its subroutine.
Any Ideas??

'THIS DOES NOT WORK:
= SortForm([Me],"CRNAME")
'The error is:
'The object doesn't contain the Automation object 'ME.'.

[Form] (or [Report]) is the equivalent of [Me] in a control
source or property expression.

--
Marsh
Feb 27 '07 #4

P: n/a
On Feb 27, 1:56 pm, Marshall Barton <marshbar...@wowway.comwrote:
ApexD...@gmail.com wrote:
I found the following code which allows me to sort on the click event
of a labelbutton.
The problem occurs when I try to call the function directly from the
ClickEvent, instead of having the ClickEvent run its subroutine.
Any Ideas??
'THIS DOES NOT WORK:
= SortForm([Me],"CRNAME")
'The error is:
'The object doesn't contain the Automation object 'ME.'.

[Form] (or [Report]) is the equivalent of [Me] in a control
source or property expression.

--
Marsh

Without the name?
I didn't know that if so.

Feb 27 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.