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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Const frmA AS Form = Forms!frmMyFancyForm ..... Public Const Object Variables Not Allowed??? 1

Status
Not open for further replies.

kjv1611

New member
Jul 9, 2003
10,758
US
I'm trying to do this in a module (not form module):
Code:
Public Const frmR = Forms!frmTocResearch
Access doesn't like it. Yet it does allow this in the same spot:
Code:
Public Const strMyString As String = "Howdy"
Is this a limitation in Access VBA, or is there some other way I CAN refer to a form this way?

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Why do you want to have a Form as a public constant?
What is the logic behind it?

Have fun.

---- Andy
 
Well... I think I'm going to be referencing a form from a subform within it with a few different procedures. Rather than using the long-names when referring to forms controls, I want to just have a short variable... and I don't want to have to type:
Code:
Dim frmA As Form
Set frmA = Forms!MyFancyForm
every time.

Make sense?

Or if there's another way when working between Form and Subform, that's great as well. [smile]

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
I FOUND A SOLUTION! I know this may sound silly, but here's what I did!

Code:
Public Function frmR() As Form
    Set frmA = Forms!MyFancyForm
End Function

Sub TestFunction()
    Debug.Print frmA.Name
End Sub

And it works! It ACTUALLY works!

[2thumbsup]

This is a good Friday for sure! [wink]

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Yep, that'd of been much easier, since that's what I'm doing the whole time anyway - referencing the parent form. Duh - I knew that but forgot, b/c I've had extremely rare cases where I needed such. Thanks for posting that solution - far better than what I did.

Also, as an update - the function I used - it worked initially, but I later ran into some hiccups, so your method would have been GREAT to use if I knew it early on. Hopefully I'll remember the next time I need it.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top