?
Solved

Pass form name to a procedure

Posted on 2003-03-12
2
Medium Priority
?
160 Views
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

e.g.

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(me.name)
fDetermineName(me)
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

Lianne

0
Comment
Question by:Lianne072600
[X]
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
2 Comments
 
LVL 43

Accepted Solution

by:
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

Or

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.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 
LVL 1

Author Comment

by:Lianne072600
ID: 8120227
Tim,

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

Lianne
0

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