List of methods of a class in intellisense - 2

KitaYama

Well-known member
Local time
Tomorrow, 02:58
Joined
Jan 6, 2022
Messages
1,885
According to the solution that was given by @MajP in this thread I use the following structure to access the methods or objects on a form;

Code:
    Dim frm as Form_MyFormName

    set frm = forms("YourFormName")
    With frm
        .     ---> List of methods are included in intellisense
    End With

While this method works, I don't know how to see the list of methods or objects of a form when the form is passed as a parameter to a function.

Code:
Public Function Drawings(frm As Access.Form)

    With frm
        .     ---> List of methods are not included in intellisense
    End With

End Function

How can I see the list of methods of a form when the form is passed to a function?
Any Kind of help is appreciated.
 
The Form class is just a generic form with generic form methods and generic properties that all forms have in common.
The Form_MyFormName class is the Form class plus whatever you have defined in its module, including the bound data, controls, variables, etc.
They are two different classes.

If you want to see the methods, declare your frm parameter as Form_MyFormName.
Public Function Drawings(frm As Form_MyFormName)
 
The Form class is just a generic form with generic form methods and generic properties that all forms have in common.
The Form_MyFormName class is the Form class plus whatever you have defined in its module, including the bound data, controls, variables, etc.
They are two different classes.

If you want to see the methods, declare your frm parameter as Form_MyFormName.
Public Function Drawings(frm As Form_MyFormName)
I thought it was obvious, but apparently it wasn't.
The same function is called from different forms. It's not always the same form calling this function.
Since the form that is passed to the function is different I can not use that method.

Thanks.
 
How can I see the list of methods of a form when the form is passed to a function?
This is done by early binding to Form_MyFormName. Early binding to just Form will display generic Form methods and properties in the intellisense list.

I thought it was obvious, but apparently it wasn't.
The same function is called from different forms. It's not always the same form.
Since the form that is passed to the function is different I can not use that method.
It is obvious and I will seem redundant to you, but that's how it works. If you're abstracting your function to expect a Form parameter by the name frm, intellisense will show you Form methods and properties for that same frm parameter, it will not display Form_MyFormName methods and properties, so do not expect that.

If you bind a form object as an object (which is what we call late bind), the IDE will not give you intellisense. There's just too many different things that can be objects.
If you bind a Form_MyFormName object as Form, the IDE will give you Form intellisense.
If you bind a Form_MyFormName object as Form_MyFormName, the IDE will give you Form_MyFormName intellisense.

Nothing stops you from declaring your frm parameter as Form_MyFormName to take advantage of that list and once you're done doing IDE stuff (writing the code), then change it back to Form. Just make sure that all forms passed to that function will have that method or property you selected from intellisense. Or handle the expected error, of course. You will benefit from looking at the locals window and seeing what I mean.

If you want intellisense it's because you're writing code, use the tool to your liking.

Or maybe I did not understand your problem?

EDIT:
I just went into the thread you're referencing and I explained the same with examples there.
 
Last edited:
Or maybe I did not understand your problem?
I think you didn't. Or I don't understand How you're trying to solve my problem.

In FormA I have:
Code:
Private Sub SF_DblClick(Cancel As Integer)
    Drawings Me
End Sub

In FormB I have:
Code:
Private Sub SF_DblClick(Cancel As Integer)
    Drawings Me
End Sub

In a Module I have:
Code:
Public Function Drawings(frm As Access.Form)

    Debug.Pring frm.name    ---> This will print FormA or FormB

    With frm
        .                       ----> List of methods are not included in intellisense
        .Trigger = "Test me"    ----> This causes error. (Trigger is a Let Property in both Forms)
    End With

End Function

I can't use something like
Public Function Drawings(frm As Form_FormA)
Because when FormB calls the function, it fails.
Thanks again.
 
Last edited:
Is the problem the error you're getting? Does that let property look something like this?
Code:
Private m_Trigger As String

Private Sub SF_DblClick(Cancel As Integer)
    Drawings Me
End Sub

Public Property Let Trigger(value As String)
    m_Trigger = value
End Property

Because that should work to assign it without having to early bind...

Note:
But you could early bind to Form_frmA or Form_frmB just to write the code and then change it back to Access.Form, it will not give you errors. And if it does, then it's probably the way your class is wired.
 
Last edited:
Is the problem the error you're getting? Does that let property look something like this?
Code:
Private m_Trigger As String

Private Sub SF_DblClick(Cancel As Integer)
    Drawings Me
End Sub

Public Property Let Trigger(value As String)
    m_Trigger = value
End Property

Because that should work to assign it without having to early bind...
Yes, that's what it looks like.
And I'm receiving Error 2465
Application-defined or object-defined error.

on this line:
.Trigger = "Test me"
 
It should work, but you could post a sample to see what the debugger says the function is working with.
 
It should work, but you could post a sample to see what the debugger says the function is working with.
I just tried it on an empty database.
It seems as you suggested accessing the methods are possible and there's no error,
But still no intellisense.


Thanks for your patient.
 
@Edgar_ Seems it was some corruption. Importing the form from a previous backup solved the error.
But still no intellisense.

Do you have a solution for showing intellisense?

Thanks.
 
Last edited:
I can't use something like
Public Function Drawings(frm As Form_FormA)
Because when FormB calls the function, it fails.
I would try conditional compilation.

You only need IntelliSense when developing. You can manually align the compilation constant to the desired object.
 
Last edited:
I would suggest to use a custom interface which provides your necessities and let your forms implement it.
Then you can cast your forms in code as you need and have full intellisense and type safety.

See my example here. Best approach is to step through the code and read my comments. Start with a breakpoint in the command buttons click event procedure.

Hope it makes it clear and helps.

Additional info:
- A class (and therefore a form) can implement several interfaces
- Several classes (and therefore also forms) can implement the same interface.
- So this approach is an abstraction which makes objects interchangeable.
 

Attachments

Last edited:
Alternatively, you could also use a class that reacts to the double-click event.
Which variant is more suitable depends on the responsibility. Both variants encapsulate a specific task.
 
@ebs17 I'm sorry, but I'm lost. I know about conditional compilation, but to be honest, I don't understand how it can be used in this situation. How the Drawing function looks like?

@AHeyne I really appreciate your sample database. I don't have Access at home and am using an IPad to remote control my work PC and moving through screens and 3 monitor is hard.
From what I see from here, after With mySpecialForm intellisense shows only Class' method (MyProperty) and none of other forms properties are listed (Name, Caption, ....). I may be doing something wrong with this small monitor. I'll check again Monday morning as soon as I'm back to my desk. Thanks.

@Josef P. I had a feeling someone will suggest this.:) I'll work on this too to see what can I do.

Thanks to all for their time and help.
 
From what I see from here, after With mySpecialForm intellisense shows only Class' method (MyProperty) and none of other forms properties are listed (Name, Caption, ....). I may be doing something wrong with this small monitor.
Thats correct, it's not you doing something wrong.
Because mySpecialForm is of type IMySpecialFormInterfaceClass, intellisense only has/shows the members of IMySpecialFormInterfaceClass in this context.

That is why I exemplary casted mySpecialForm to the type Form (variable myForm), to show that you can 'switch' the object variable to what you need.
 
@AHeyne I had never done polymorphism in VBA. OP wanted the intellisense to show with the same frm variable, but the interface solves it with just an additional variable.

Did my own example out of inspiration. In my version, I show the added benefit of abstracting it like that, which is being able to employ different mechanisms to get to the same place, or different place, depending on the need. Just in case someone wonders why they would do this.

The object you pass to the function must implement the interface, or it will not be able to be passed. That I think is important to mention.

Thanks for the example, this is the code:
IFormWidth:
Code:
Public Property Get GetFormWidth() As Variant
End Property

Form_frmPeople
Code:
Implements IFormWidth

Private Sub Form_Load()
    Me.txtWidth = ShowWidth(Me)
End Sub

Private Property Get IFormWidth_GetFormWidth() As Variant
    IFormWidth_GetFormWidth = Me.InsideWidth
End Property

Form_frmPlaces
Code:
Implements IFormWidth

Private Sub Form_Load()
    Me.txtWidth = ShowWidth(Me)
End Sub

Private Property Get IFormWidth_GetFormWidth() As Variant
    IFormWidth_GetFormWidth = Me.Width
End Property
Notice I'm using a different method to get the value.

Some module:
Code:
Public Function ShowWidth(param As IFormWidth) As Long
    
    ' turn into form
    Dim frm As Form
    Set frm = param
    
    ' use interface
    ShowWidth = param.GetFormWidth
    
    'can still use frm props
    Debug.Print "From the frm variable: " & frm.WindowWidth
    
End Function
 

Attachments

It's great that you've recognized the advantages of the approach and can use them for yourself. That's how it should be. :-)
 
you can create a Class (form class) and moved the Public Property to that class.

you need to change your function declaration to:

Code:
Public Function Drawings(frm As clsForm)
then you can see your public Property in intellisence. (but not all the other property).
 
Debug.Pring frm.name
You spell print the same way that I do:ROFLMAO::ROFLMAO::ROFLMAO:

I don't understand why you need to see a list of the form's methods.

The whole point of using this technique is because what you are doing doesn't change whether the data is in formA or formB. The code is in your module. It is just the data that is in formA and formB that you are referencing. Not any of the form's methods.
 

Users who are viewing this thread

Back
Top Bottom