Solved List of methods of a class in intellisense

KitaYama

Well-known member
Local time
Tomorrow, 05:44
Joined
Jan 6, 2022
Messages
1,885
I have a form with several public methods.

Code:
Private m_PK As Long

Public Property Get PK() As Long
    PK = m_PK
End Property

Public Property Let PK(ByVal NewValue As Long)
    m_PK = NewValue
End Property

When I open the form as following, intellisense doesn't show the list of methods.

Code:
    DoCmd.OpenForm "frm"
    With Forms("frm")
        .
    End With

But if I add a class module and do the same, after instantiating the class, I have the list of all methods in inellisense.

Isn't a form module just like a class module? Shouldn't both behave the same?
Or am I missing some steps here?

Thanks for any kind of guidance/advice.
 
Solution
You need to subclass the form. Declare it as a specific form not a general form.

Code:
Dim frm as Form_YourFormName
docmd.openForm "yourFormName"
set frm = forms("YourFormName")
frm. intellisense for all properties, methods here.
You need to subclass the form. Declare it as a specific form not a general form.

Code:
Dim frm as Form_YourFormName
docmd.openForm "yourFormName"
set frm = forms("YourFormName")
frm. intellisense for all properties, methods here.
 
Last edited:
Solution
You can also open it with less code, without the docmd
Code:
Dim frm as NEW Form_YourFormName 'instantiate a new instance of your form but not visible
frm.visible = true
frm. intellisense for all properties, methods here.
 
Posted code works for me using a real form name in place of frm. If frm was intended to be a variable, variable cannot be within quote marks.
 
Here is an example. See the difference in how I declare the frm.
No "HelloWorld"
hw1.png

Same code declared as Form_Form1
hw2.png
 
You need to subclass the form. Declare it as a specific form not a general form.

Code:
Dim frm as Form_YourFormName
docmd.openForm "yourFormName"
set frm as forms("YourFormName")
frm. intellisense for all properties, methods here.
@MajP Million thanks for the advice.

Just for others who refer to this thread in future, you may want to correct the typo you have.
It should be set frm = forms("YourFormName")
 
Posted code works for me using a real form name in place of frm. If frm was intended to be a variable, variable cannot be within quote marks.
Though my question was solved by majp, I'd really like to see what you meant and how it worked for you.
A sample database is attached. Open Module1. It contains only one sub.
Does intellisense shows the method after With?

thanks.
 
Yes, I get intellisense just by typing dot.
Is PK method listed in the intellisense?
May I ask your Access version?
Can it be because of the difference in VBA libraries or is it something wrong on my side....

Can anybody else check if intellisense works in sample database in #7?

It's what Access gives me in Microsoft 365 version 2304 Build 16.0.16327:
And as you see, PK method is not listed.

2023-10-30_09-45-01.png


thanks.
 
Last edited:
I believe you and June are talking two completely different things. You are talking about visibility of form specific properties and methods. June is simply talking about intellisense.
 
Ooops, I missed that you wanted to see custom class properties\methods. I never worked with custom classes. This shows the PK property:
Code:
Sub test()
    DoCmd.OpenForm "frm"
    With Form_frm
        .PK
    End With
End Sub
 
Is PK method listed in the intellisense?
May I ask your Access version?
Can it be because of the difference in VBA libraries or is it something wrong on my side....

Can anybody else check if intellisense works in sample database in #7?

It's what Access gives me in Microsoft 365 version 2304 Build 16.0.16327:
And as you see, PK method is not listed.

View attachment 110652

thanks.

At that point, all Access knows is Forms("frm") is a form class. It will display intellisense for a generic form object/class because Forms("frm") defaults to Forms("frm").Form, and that is a form object. If you want to get intellisense for properties declared in the form, you'd have to refer to the class name, your form has a class name like Form_frm, so if you're looking for the properties of the Form_frm class, all you have to do is declare a variable of type Form_frm.

Do this in the code of your form:

Code:
Public Property Get KitaYama() As Boolean
    KitaYama = True
End Property

And in your module
Code:
Sub test()
    Dim someVariable As Form_frm
    With someVariable
        'type the point and look for the KitaYama property
    End With
End Sub

Now, of course, that gives you intellisense for that class, but it is not initialized yet, so it will do nothing. However, if you set it to an object of type Form_frm, which your form "frm" is, it will work. But if you set it to an object of type, say "Form_OtherForm", which is the case if you create a form with "OtherForm" as name, then it will throw a type mismatch.

This fails:
Code:
Sub test()
    Dim someVariable As Form_frm
    Set someVariable = Forms("OtherForm")
    With someVariable
        'type the point and look for the KitaYama property
        MsgBox.KitaYama
    End With
End Sub

This works:
Code:
Sub test()
    Dim someVariable As Form_frm
    Set someVariable = Forms("frm")
    With someVariable
        'type the point and look for the KitaYama property
        MsgBox.KitaYama
    End With
End Sub

If you run the form, though, like Forms("frm"), you will get the KitaYama property, because at that point, the Form_frm is initialized and running with its full set of properties. But that's at runtime, remember. You can get its properties if it's running, but not intellisense.

And if you do this in a module or whatever:
Code:
Sub Something()
    Form_frm.
            ^ dot
End Sub
You'll get intellisense for that form, the KitaYama property will appear

TL;DR
Your forms have a type, it is Form_TheFormNameYouGaveIt, if you want to access its properties, you'll have to refer to said class.
 
Last edited:
At that point, all Access knows is Forms("frm") is a form class. It will display intellisense for a generic form object/class because Forms("frm") defaults to Forms("frm").Form, and that is a form object. If you want to get intellisense for properties declared in the form, you'd have to refer to the class name, your form has a class name like Form_frm, so if you're looking for the properties of the Form_frm class, all you have to do is declare a variable of type Form_frm.

Do this in the code of your form:

Code:
Public Property Get KitaYama() As Boolean
    KitaYama = True
End Property

And in your module
Code:
Sub test()
    Dim someVariable As Form_frm
    With someVariable
        'type the point and look for the KitaYama property
    End With
End Sub

Now, of course, that gives you intellisense for that class, but it is not initialized yet, so it will do nothing. However, if you set it to an object of type Form_frm, which your form "frm" is, it will work. But if you set it to an object of type, say "Form_OtherForm", which is the case if you create a form with "OtherForm" as name, then it will throw a type mismatch.

This fails:
Code:
Sub test()
    Dim someVariable As Form_frm
    Set someVariable = Forms("OtherForm")
    With someVariable
        'type the point and look for the KitaYama property
        MsgBox.KitaYama
    End With
End Sub

This works:
Code:
Sub test()
    Dim someVariable As Form_frm
    Set someVariable = Forms("frm")
    With someVariable
        'type the point and look for the KitaYama property
        MsgBox.KitaYama
    End With
End Sub

If you run and the form, though, like Forms("frm"), you will get the KitaYama property, because at that point, the Form_frm is initialized and running with its full set of properties. But that's at runtime, remember. You can get its properties if it's running, but not intellisense.

And if you do this in a module or whatever:
Code:
Sub Something()
    Form_frm.
            ^ dot
End Sub
You'll get intellisense for that form, the KitaYama property will appear

TL;DR
Your forms have a type, it is Form_TheFormNameYouGaveIt, if you want to access its properties, you'll have to refer to said class.
Thanks for details.
 
Simple rule: Intellisense only works with early binding of the respective (declared) class/interface.

Code:
dim frm as Form_Frm
docmd.OpenForm "frm"
set frm = forms("frm")
frm.   => Intellisense will list all public/friend methods and properties of Form_Frm

---

dim frm as Form_Frm
set frm = New Form_Frm
frm.   => Intellisense will list all public/friend methods and properties of Form_Frm

' or

With New Form_Frm
   .   => Intellisense will list all public/friend methods and properties of Form_Frm

---

dim frm as Form ' <--- use only Form interface
docmd.OpenForm "frm"
set frm = forms("frm")
frm.   => Intellisense will list all methods and properties of the Form interface and not the special additions of Form_Frm.
 
public/friend methods and properties of Form_Frm
I've read about Friend methods/functions in classes long time ago. I think I need to refresh my memory about the difference between public & friend.
I do some readings and will back if I have additional questions on this regard.

Thanks for taking your time and helping.
 
"special additions"
I meant all methods and properties added to the class Form_Frm.

[OT: public / friend]
Not quite correct, but easy to remember described: Friend is Public inside the current VBProject and Private outside.
All Codemodules inside a VBProject are friends - therefore they are allowed to use the methods/properties declared as (only for) Friend. ;)
 

Attachments

Last edited:
"special additions"
I meant all methods and properties added to the class Form_Frm.

[OT: public / friend]
Not quite correct, but easy to remember described: Friend is Public inside the current VBProject and Private outside.
All Codemodules inside a VBProject are friends - therefore they are allowed to use the methods/properties declared as (only for) Friend. ;)
Appreciated.
 

Users who are viewing this thread

Back
Top Bottom