Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2009, 06:45 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 131
Thanks: 10
Thanked 0 Times in 0 Posts
Default Form name as variable

Hi,

I have a routine that is used within several forms and I would like to contain it in a separate module which is referenced by each form.to cut down on coding.

Is there a method that I could perform the following 'With' statement (and similar) using a variable?


Code:
Call MySub("MyFormName")
Code:
 
Public Sub MySub(strFormName as String)
Dim nextRow As Integer
nextRow = getGenericRows()
nextRow = nextRow + 1
With strFormName.fmeGeneric
    'MyCode
End With
 
End Sub
strFormName = The name of the form held as a string
fmeGeneric = A frame within the form

Maybe both the form and frame should be passed as the parameter?

Thanks in advance,
__________________
Neal

A Northern Soul
 
Old September 25th, 2009, 10:26 AM
JP JP is offline
Authorized User
 
Join Date: Apr 2008
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Pass a copy of your Form object to the procedure.

Code:
 
Public Sub MySub(strFormName as MSForms.UserForm)
Dim nextRow As Integer
nextRow = getGenericRows() + 1
With strFormName.fmeGeneric
    'MyCode
End With
 
End Sub
To call this procedure from the code module behind a form, just use

Call MySub(Me)

You can cut and paste this line into any form's code module without modification, since the Me keyword will always refer to the current form.

--JP

Quote:
Originally Posted by Neal View Post
Hi,

I have a routine that is used within several forms and I would like to contain it in a separate module which is referenced by each form.to cut down on coding.

Is there a method that I could perform the following 'With' statement (and similar) using a variable?


Code:
Call MySub("MyFormName")
Code:
 
Public Sub MySub(strFormName as String)
Dim nextRow As Integer
nextRow = getGenericRows()
nextRow = nextRow + 1
With strFormName.fmeGeneric
    'MyCode
End With
 
End Sub
strFormName = The name of the form held as a string
fmeGeneric = A frame within the form

Maybe both the form and frame should be passed as the parameter?

Thanks in advance,
__________________
Regards,
JP
JP SoftTech
The Following User Says Thank You to JP For This Useful Post:
Neal (September 28th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
To pass value of string variable to another form thillai Visual Basic 2005 Basics 5 March 13th, 2008 03:29 AM
passing a variable from one form to another madhukp VB How-To 4 January 19th, 2005 12:45 AM
How to pass a variable form one form to the next Dinesh22 VB.NET 2002/2003 Basics 1 January 8th, 2004 08:55 PM
php not printing variable from a form ebmsynthpop Beginning PHP 2 June 22nd, 2003 01:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.