Pass form name to avoid ME keyword

G

Guest

Office 2003, XP Pro SP2

I have a series of forms that all use two-listbox methodology for selecting
data from 1st list box and pushing it to 2nd list box. The code is attached
to a command button and comes from the MS KB as follows:

Private Sub MoveAllItems(strSourceControl As String, strTargetControl As
String)
Dim strItem As String
Dim intColumnCount As Integer
Dim lngRowCount As Long



For lngRowCount = 0 To Me.Controls(strSourceControl).ListCount - 1
For intColumnCount = 0 To Me.Controls(strSourceControl).ColumnCount
- 1
strItem = strItem &
Me.Controls(strSourceControl).Column(intColumnCount, lngRowCount) & ";"
Next
strItem = Left(strItem, Len(strItem) - 1)
Me.Controls(strTargetControl).AddItem strItem

strItem = ""
Next

Me.Controls(strSourceControl).RowSource = ""
End Sub

Which works fine as a "Private Sub" on each form.

I would like to move this to a "Public Sub" in a module (so it's only in my
db 1 time instaed of once for each form), but I can't figure out how to pass
the form name to avoid the 'ME' keyword. Simply removing the 'Me' off the
"me.Controls" doesn't work, and while I've tried several versions of
passing/using the form name:(
Sub MoveAllItems(strFormName as string,strSourceControl As String,
strTargetControl As String)

strFormName .Controls(strTargetControl).AddItem strItem
AND
[Forms]![strFormName].Controls(strTargetControl).AddItem strItem
AND
[Forms]![ & strFormName & ].Controls(strTargetControl).AddItem strItem

etc..
I can't figure out how to get the form name into the Public sub.

I'd appreciate any references/answers that will help me get past this.

BAC
 
A

Albert D. Kallal

Call call the rouinte..and pass the form...


Call MyCoolSub(me)


Then, in your code:

Private Sub MoveAllItems(f as form,
strSourceControl As String,
strTargetControl As String)

For lngRowCount = 0 To f.Controls(strSourceControl).ListCount - 1

as above..just change "me" to "f"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top