Pass form name to a procedure

Posted on 2003-03-12
Medium Priority
Last Modified: 2010-04-07
I am hoping one of you experts will be able to help me. I want to pass the name of the form calling the procedure


Public Function fDetermineName(sName as String) as String
Dim s as String
   s = sName
   s.txtName = fGetUserID

End Sub

I have tried all of the following: -
fDetermineName("Name of Form")

I am probably doing the whole thing wrong, but I thought the form name needed to be passed in as a string argument. I will appreciate any help with this, there are only so many diferant configurations I can try before I drive myself insane!!

Thanks in advance


Question by:Lianne072600
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 43

Accepted Solution

TimCottee earned 600 total points
ID: 8120068
Hi Lianne,

You can do it one of two ways:

Public Function fDetermineName(sName As String) As String
Dim s As Form
Set s = Forms(sName)
s.txtName = fGetUserID


Public Function fDetermineName(ByRef sName As Form) As String
Dim s As Form
Set s = sName
s.txtName = fGetUserID

Either way works, the idea being that if you pass the form's name as a string you then need to identify the actual form object in the forms collection. However if you pass the form as an object, calling the function as MsgBox fDetermineName(Me) for example then you are passing a reference to the actual form object itself and you can then manipulate any of its properties and methods in the function.


Brainbench MVP for Visual Basic

Experts-Exchange Advisory Board Member

Author Comment

ID: 8120227

Thats excellent, thanks a lot and such a rapid response. Thanks again.


Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question