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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Form Name 1

Status
Not open for further replies.

timb94

Programmer
Apr 20, 2004
58
US
Happy New Year everyone.

I have the following subroutine in a VAB module and it works with no problem.

Public Sub HideUnhide(ByVal blnHidUnhide as Boolean, strPage AS String)

For Each ctl In Forms!frmMyForm!("TabCtl12").Pages(strpage).Controls
Select Case ctl.ControlType
Case acCommandButton
If blnhidunhide Then
ctl.visible = false
else
ctl.visible = true
end if
End Select
Next

What I need to do is to make this a generic routine where I can pass in the form name as part of the call.

I think it would be something like this but I'm not sure.

Public Sub HideUnhide(ByVal blnHidUnhide as Boolean, strPage AS String, frmForm as form)

For Each ctl In Forms!frmForm!("TabCtl12").Pages(strpage).Controls

I've tried a couple of different variations of the above and I can't seem to get the syntax right.

Could someone pleawe point me in the right direction?

Thanks
 
You can add a "frmName as Form" to:
Code:
Public Sub HideUnhide(ByVal blnHidUnhide as Boolean, strPage AS String, frmName as Form)
and pass in the form name
 
Thank you CaptainD

Two questions:
1. On the call statement how would I define the form.
HideUnhide True, ????????

2. Once I have passed the form name into the procedure, would the For/Next read something like I have stated in my post? Just replace the Forms!frmForm with the variable in the procedure statement? It would read Forms!frmName!etc.etc.

Thanks again.
 
Tim, If you're passing the form itself, you'll use the form object you passed...

It would be something like

Code:
 for each ctl in frmName.controls
  .......

You're thinking of referencing by name, where you're passing the form name....

CaptainD is showing you how to add the parameter which expects a form to be passed.

Randall Vollen
Merrill Lynch
 
why not simply this ?
Public Sub HideUnhide(ByVal blnHidUnhide as Boolean, strPage AS String, frmName As Form)
For Each ctl In frmName.Pages(strpage).Controls
If ctl.ControlType = acCommandButton Then
ctl.Visible = blnhidunhide
End If
Next
End Sub

And an example of calling:
HideUnhide True, "Page2", Me

or:
HideUnhide False, "PageX", Forms("MainFormName")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV.

This was what I was thinking of. I knew I had all the right pieces but wasn't sure of the syntax.

I coded the following in a test module but I'm still having a problem.

dim frmName as form
set frmname = forms("frmmobile")
dim strpage as string
strpage = "building"

For Each ctl In frmName.Pages(strpage).Controls
..
..
Next

Its giving me a compile error on the .Pages portion of the For statement.

The error is "Wrong number of arguments or invalid property assignment"

Is there something else that I'm missing?

Sorry to be such a pest.
 
Please ignore my last post.

This is being run for a Tab control. How do I incorporate this into the For/Next statement or do I need to worry about that?

If I code the following in a test module I get an error on frmName: "Type-declaration character does not match declared data type". I've tried both "!" and ".".

Dim frmName As form
Set frmName = Forms("frmmobile")
Dim strPage As String
strPage = "building"
Dim strTab As String
strTab = "tabctl2"

For Each ctl in frmName!(strtab).Pages(strpage).controls
..
..
Next


If I use PHV's code it gives me an error saying that its the "wrong number of arguments or invalid property assignment".

Sorry for being such a pest.

Thanks for any help.
 
And this ?
For Each ctl in frmName(strTab).Pages(strPage).Controls

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Perfecto PHV

I need to do a little cleanup but this will allow me to consolidate a number of procedures.

A star for you.

Also thanks to CaptainD and hwkranger for your response.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top