Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a form as a parameter to a module

Status
Not open for further replies.

h3lm3t

Technical User
May 27, 2003
16
0
0
GB
Hit there thanx for looking, i need help in passing a form to a module. Ive made a module that deals with navigation and 2 buttons that are common across 10 forms.

What im trying to do is pass the form that currently has focus, so i can use the underlying module code.

in the form control button I tryed:

Private Sub cmdAdd_Click()

MyModule.cmdAdd_Click (Form_frmElectrician)

End Sub

------------
in the module:

Option Compare Database
Dim formName As Forms



Public Sub cmdAdd_Click(formName As Form)


On Error GoTo Err_cmdAdd_Click

Me.AllowAdditions = True
cmdclose.SetFocus
currentForm.cmdAdd.Visible = False
currentForm.cmdEdit.Visible = False
currentForm.cmdclose.Caption = "Close"

blah, blah

Hopefully you can see what im trying to do :cool:

Thanx in advance for any and all help.
Kind regards

h3lm3t
 

Am I right in thinking that you have a seperate form with the navigation buttons on and 10 or so other forms that could be open at the same time. When you press the Add button, it uses that form that had the focus.
 
Hey Paulo, i think ive made the questsion too hard, and because of that no-one gets wgat i mean, (not even me) ;-)

I'll start again.

Simply, how can you use a module in all forms. I mean actualy use a specific form in the module, when you dont know the form name beforehand. Can you use a string that passes the form name into the module so that generic form operations can be performed on the string (but its actually referencing the form)

in the form
=============
Private Sub cmdAdd_Click()

MyModule.cmdAdd_Click ("frmAnyForm") ' a module procedure that is passing in a specific forms name


in the module
=======================

Public Sub cmdAdd_Click(anyFormName As String)


On Error GoTo Err_cmdAdd_Click

anyFormName.AllowAdditions = True ' a property of all my forms
anyFormName.SetFocus
anyFormName.cmdAdd.Visible = False


End Sub


I hope ive explained this ok this time, thanx for trying to help though.
cheers

h3lm3t
 
Hi h3lm3t,

You seemed to be almost there to start with. How was Form_frmElectrician defined? It needs to be a Form.

If you always want to pass the form you are calling from you should be able to use:

MyModule.cmdAdd_Click(Me)

If you want to pass a different form you will need to explicitly name it (unless you already have some reference to it) like:

MyModule.cmdAdd_Click(Forms![FormName])

Enjoy,
Tony
 
Hi Tony, again you have helped me, thank you very much sir!!!!

o doubt i will be asking of your knowledge again.

kind regards

h3lm3t
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top