By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,454 Members | 2,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,454 IT Pros & Developers. It's quick & easy.

how to pass a form as parameter

P: 11
I am trying to pass a form as a parameter in a function. How can i do that?

I have tried function( frm as Form) then on the calling routing i try to use
private sub callingRoutine()
Dim frm1 as Form
set frm = Me
callFunction(frm)
end sub

This fails either on the calling routine or when i get into the function that needs to use the form. I get various errors depending on how i am hacking the code.

Thanks
Nov 25 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 1,287
I know you can do this:

callFunction(Me.Name)
-----------------------------------------
Public callFunction(strFormName as String)
Forms(strFormName).Visible = True
'or whatever you want to do on the form.

Hope that helps.
Nov 25 '08 #2

FishVal
Expert 2.5K+
P: 2,653
Hello, ofilha.

Actually your approach is quite right.
However, it seems to me you have a syntax problems.
Could you post the code exactly as it looks?
Nov 25 '08 #3

ADezii
Expert 5K+
P: 8,597
As stated by FishVal, your approach is correct, but your Syntax is not!
Expand|Select|Wrap|Line Numbers
  1. Private Sub CallingRoutine()
  2. Dim frm1 As Form
  3.  
  4. Set frm1 = Me
  5.  
  6. '*** Either Call Routine will work ***
  7. Call fTestFormParameter(frm1)
  8. Call fTestFormParameter(Me)
  9. '*************************************
  10. End Sub
Expand|Select|Wrap|Line Numbers
  1. Public Function fTestFormParameter(frmForm As Form)
  2.   MsgBox "The Caption of the passed Form is " & frmForm.Caption
  3. End Function
P.S. - CallingRoutine() is Private to the Form while fTestFormParameter() is a Public Function in a Standard Code Module. fTestFormParameter() can also be Private within the context of the Form where CallingRoutine() resides.
Nov 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.