?
Solved

Passing Form name to module

Posted on 2004-10-10
8
Medium Priority
?
142 Views
Last Modified: 2010-05-02
Hi - is there  a way in which to pass a form name to a module where the command executed can be multiple form names?

I know that you can pass general variables, like Caption; however, I am unable to hide specific label.

I didn't want to have to duplicate the code for each form.

Thanks for the help.

Information:
I have two forms: frmCommercial and frmTechnical.  Both forms have a label called "lbl1a".  

'frmCommercial
Private Sub Command1_Click()
     Call fGetFormName(frmCommercial)
End Sub

'frmTechnical
Private Sub Command1_Click()
     Call fGetFormName(frmCommercial)
End Sub

'------ module -----------------------------
'one module that used for multiple forms
Function fGetFormName(iform As Form)    
    iform.lbl1a.visable = True  <---------- THIS IS WHERE I GET THE ERROR, Run-time error 438
End Function
0
Comment
Question by:eciabattari
[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
8 Comments
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 1000 total points
ID: 12272380
In both forms change the code to

Private Sub Command1_Click()
     Call fGetFormName(Me)
End Sub

and

    iform.lbl1a.visable = True  
should read
    iform.lbl1a.visible = True  
0
 
LVL 5

Expert Comment

by:waelothman
ID: 12272383
you can pass Me.Name as string to the function
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12272394
How about passing the form name instead of the form itself?  You can then use an If or Case to set the correct label's visible property.  Something like:

Function fGetFormName(strFormName as String)
    if strFormName = frmCommercial Then
        frmCommercial.Lbl1a.Visible = True
    Else
        frmTechnical.Lbl1a.Visible = True
    End If
End Function

As a side note, I can't help but notice that in your code you've misspelled "visible" as "visable" and that you're using a function to accomplish this but don't appear to be returning anything.  Are you sure that's not the source of your error?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:eciabattari
ID: 12272406
Thanks... worked perfect.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12272428
PS: the reason you get this error at run time and not at compile time is due to late binding the form/control.

If you wanted to make use of intellisense/compiler early bound error checking you could have done something like this:

Function fGetFormName(iform As Form)    
    Dim lbl1a As VB.Label

    Set lbl1a = iform.lbl1a
    iform.lbl1a.Visible = True
    Set lbl1a = iform.lbl1a
End Function

Another clue would have been when the initial v wasn't capitalised in the word "visable".

Also, Why do you do this in a Function, wouldn't a Sub be better. A sub returns void (in C parlance) but this Function retuns an implicitly declared variant.

While I'm at it,  

    iform.lbl1a.visible = True

actually shows the label - if you want to hide it try
    iform.lbl1a.visible = False
 
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12272453
BDF:

>> How about passing the form name instead of the form itself?  You can then use an If or Case to set the correct label's visible property.  Something like:<<

Why do that? VB string handling is poor and passing a form name would require creating a creating a new memory buffer, copying the string into it and passing the pointer to the string as a Long Integer.

Passing the Form reference is much neater. You just pass the Object pointer to the form Long Int. Also if you pass the Form reference, it is easy to get the name of the form. Passing the form name will not work in MDI environments where you might get two instances of the same form with the same name.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12272521
"Why do that?"
Because some folks find it easier conceptually to deal with the name of something than with an object reference.  I was illustrating the idea of passing something other than the object itself.  The passed item didn't have to be a string,it could've been a number (0 for one form and 1 for the other), etc.  

"Passing the form name will not work in MDI environments where you might get two instances of the same form with the same name."
You're absolutely correct.  
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12272985
Fair enough.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 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