how do I refer to Me as a form

smig

Registered User.
Local time
Tomorrow, 01:43
Joined
Nov 25, 2009
Messages
2,209
I'm trying to use this code

Code:
dim frmFormName as Form
frmFormName = Me

but I get an "Invalid use of property" error

also tried this, but with the same result (ControlName is the name of one of the controls on the form)
Code:
dim frmFormName as Form
frmFormName = Me.ControlName.Parent
 
A form is an object so you must Set it.

Set frmFormName = Me
 
I have another related problem

I'm trying to put this code in one of the object's OnMouseMove event
=pbSetOptionsBtnProperties([me],"btnIcon_MovePrev",2)

but I get an error:
The object doesn't contain the automatation object 'me.'
 
Surely one shouldnot use Me as a formname, I may be getting old and forgetful but isn't Me used by Access VBA to refer to the current object
ie Me.Fred refers to the control Fred in the current form.


Brian
 
I refer to Me as the form object, not the form name.
in the pbSetOptionsBtnProperties function it expact to get a form (frm as Form)
 
Try:-

=pbSetOptionsBtnProperties([Form],"btnIcon_MovePrev",2)

though, depending on what you are doing, you may not need it.

Chris.
 
Chris, that's pretty cool.
I didn't know you could get an object reference in the OnEvent function call like that.
Mark
 
Sometimes we don’t need to pass the Form object…

If btnIcon_MovePrev is the name of a Control on the Form:-

=pbSetOptionsBtnProperties([btnIcon_MovePrev],2)

Code:
Private Function pbSetOptionsBtnProperties(ctl As Control, num As Long)

    [color=green]' To set the Caption of the Control.[/color]
    ctl.Caption = num
    
    [color=green]' To set the Caption of the Form.[/color]
    ctl.Parent.Caption = num
    
End Function

So the Form reference can be derived from the Parent of the Control, even on a sub-form.

Chris.
 
Thank you Chris
I knew you will help me here as you'r the master of this :D

The truth is I don't need the form at all, and it's good to know I can directly refernce the control.

How can I refernce sections of the forms - detail, header and footer ?
also how can I reference to all other controls ?
I'm trying this but it's not working:
Code:
[FONT=Courier New]For Each ctl In Me.Controls
    With ctl
        Select Case .name
            Case "btnIcon_MovePrev"
                .OnMouseMove = "=pbSetOptionsBtnProperties([btnIcon_MovePrev], 2)"
            Case "btnIcon_MoveNext"
                .OnMouseMove = "=pbSetOptionsBtnProperties([btnIcon_MoveNext], 2)"
            Case Else
                .OnMouseMove = "=pbSetOptionsBtnProperties([" & ctl & "], 0)"
        End Select
    End With
Next ctl
[/FONT]
[FONT=Courier New]Me.Detail.OnMouseMove = "=pbSetOptionsBtnProperties([Detail], 0)"

[/FONT]
 
Last edited:
I think I’ve mentioned this before but in order to be a valid Event Property string the string needs to be a valid string at runtime.

So at runtime this is not a valid string:-
"=pbSetOptionsBtnProperties([" & ctl & "], 0)"
because ctl can not be evaluated as a string at runtime; it’s a Pointer to the control.

Therefore when testing, try placing this within the loop:-
MsgBox "=pbSetOptionsBtnProperties([" & ctl & "], 0)"
It will compile but it will not run.

Also, a Control is recognised as a Control (naturally) but a Section is not.
But we can receive both as a Variant and that Variant has a Name property…

Code:
Option Explicit
Option Compare Text


Private Sub Form_Open(ByRef intCancel As Integer)
    Dim ctlControl As Control
    Dim lngSection As Long

    Const conHandler As String = "=pbSetOptionsBtnProperties(["
    
    For Each ctlControl In Me
        With ctlControl
            Select Case .Name
                Case "btnIcon_MovePrev", "btnIcon_MoveNext"
                    .OnMouseMove = conHandler & ctlControl.Name & "], 2)"
                
                Case Else
                    On Error Resume Next
                        .OnMouseMove = conHandler & ctlControl.Name & "], 0)"
                    On Error GoTo 0
            End Select
        End With
    Next ctlControl
    
    For lngSection = 0 To 4
        On Error Resume Next
            Me.Section(lngSection).OnMouseMove = conHandler & Me.Section(lngSection).Name & "], 0)"
        On Error GoTo 0
    Next lngSection
    
End Sub


Private Function pbSetOptionsBtnProperties(ByVal Vnt As Variant, _
                                           ByVal Num As Long)
    
    Static lngCount As Long

    Select Case Vnt.Name
        Case "btnIcon_MovePrev", "btnIcon_MoveNext"
            [color=green]' Do the 2 stuff.[/color]
            lngCount = lngCount + 1
            Me.txtIterations = lngCount
        
        Case Else
            [color=green]' Do the 0 stuff.[/color]
            lngCount = lngCount - 1
            Me.txtIterations = lngCount
            
    End Select

End Function

Chris.
 
Thanks,

just to make sure I understand corectly.
Is the Control.Name treated as a control (Not the control name) because I send it inside the square brackets ?
IE are these the same ?
Case "btnIcon_MovePrev", "btnIcon_MoveNext"
.OnMouseMove = "=function([" & ctlControl.Name & "])"


Case "btnIcon_MovePrev", "btnIcon_MoveNext"
.OnMouseMove = "=function([btnIcon_MovePrev])"
 
Smig,
I am not sure what the end game is here, but you might want to try Me.Form.Name, as a reference to the property. That phrase will give you the name of the current form. Often I use it with with haha then you can copy stuff like this to any form and it will grab that form's name.
With Me.Form.Name
.Filter = Date
.FilterOn = True
end with
Hope that helps
Michael
 
Michael,
I think you totaly missed the point here.
I don't want the form name (a string) but the form object (a form)

when you use the form (as object) it will refer to it even when it's a subForm.




back to my previous question.
It works like I need.

I'm learning fast when you explain slow and several times :D

Thanks again Chris
 
Is the Control.Name treated as a control (Not the control name) because I send it inside the square brackets?

No, in this case you can remove the square brackets. If the control name has some illegal character in it, such as a space or period, then the square brackets will be inserted for you. So the square brackets are there to fix illegal control names. The square brackets tell the compiler to regard the contents literally as a string without having quotation marks around the string. So we could say that the control name will be regarded as a name if it is surrounded by quote marks else it will be regarded as a pointer to the object.



IE are these the same ?
Case "btnIcon_MovePrev", "btnIcon_MoveNext"
.OnMouseMove = "=function([" & ctlControl.Name & "])"

Case "btnIcon_MovePrev", "btnIcon_MoveNext"
.OnMouseMove = "=function([btnIcon_MovePrev])"

Yes.
Edit:
Except for the fact that btnIcon_MovePrev only refers to btnIcon_MovePrev and not btnIcon_MoveNext.



Chris.
 
Last edited:
Thanks again :)

so this is what make the difference:
=function([" & ctlControl.Name & "]) ' Control as object
=function([" & Chr(34) & ctlControl.Name & Chr(34) & "]) ' Control as name
 
No, it would be:-
.OnMouseMove = "=pbSetOptionsBtnProperties(" & Chr(34) & "[" & ctlControl.Name & "]" & Chr(34) & ")"

I think you should be testing some of this because you can not have a Function by the name of function.

Chris.
 

Users who are viewing this thread

Back
Top Bottom