Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Pass form name to a procedure

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

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

572 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