Treating my subform as a control

E

Eric D. Braden

I have written a module with a sub called nearestCtrl which accepts
two arguments. One is as a Form and the other as a Control. My
problem is that both arguments are referring to the same subform. But
each, obviously, refers to a different "state" or object related to
the subform (my VBA understanding begins to break down here). I am
able to just put "Me" in for the form argument, but I have to input
the full path of the subform for the control (like
Me.Parent.f_subSubForm). Is it possible to somehow just put in the
Form argument and somehow load up the Control aspect from within the
function?

So that calling it would just be "nearestCtrl(Me)" instead of
"nearestCtrl(Me, Me.Parent.f_subSubForm)"?


This is the sub:

-code-

Public Sub nearestCtrl(meCtrl As Form, thisCtrl As Control)

Dim ctrlGold As Control
Dim ctrlCurrent As Variant
Dim bruteNum As Long
Dim ctrlTest As Control
Dim ctrlGoldTop As Long

ctrlGoldTop = 100000
For Each ctrlTest In meCtrl.Parent.Controls
If (bruteNum = 0) Then
Set ctrlGold = ctrlTest
Else
If (ctrlTest.ControlType <> acLabel) Then
If (ctrlTest.Top - thisCtrl.Top > 0 And ctrlTest.Top - thisCtrl.Top <
ctrlGoldTop - thisCtrl.Top) Then
ctrlGoldTop = ctrlTest.Top
Set ctrlGold = ctrlTest
End If
End If
End If
bruteNum = bruteNum + 1
Next ctrlTest
MsgBox (ctrlGold.Name & " is Gold")
End Sub

-end code-

Oh, also, the code is intended to find the nearest control below the
one the function is called in. Thanks in advance for any advice!
 
D

david couasme

Eric D. Braden said:
I have written a module with a sub called nearestCtrl which accepts
two arguments. One is as a Form and the other as a Control. My
problem is that both arguments are referring to the same subform. But
each, obviously, refers to a different "state" or object related to
the subform (my VBA understanding begins to break down here). I am
able to just put "Me" in for the form argument, but I have to input
the full path of the subform for the control (like
Me.Parent.f_subSubForm). Is it possible to somehow just put in the
Form argument and somehow load up the Control aspect from within the
function?

So that calling it would just be "nearestCtrl(Me)" instead of
"nearestCtrl(Me, Me.Parent.f_subSubForm)"?


This is the sub:

-code-

Public Sub nearestCtrl(meCtrl As Form, thisCtrl As Control)

Dim ctrlGold As Control
Dim ctrlCurrent As Variant
Dim bruteNum As Long
Dim ctrlTest As Control
Dim ctrlGoldTop As Long

ctrlGoldTop = 100000
For Each ctrlTest In meCtrl.Parent.Controls
If (bruteNum = 0) Then
Set ctrlGold = ctrlTest
Else
If (ctrlTest.ControlType <> acLabel) Then
If (ctrlTest.Top - thisCtrl.Top > 0 And ctrlTest.Top - thisCtrl.Top <
ctrlGoldTop - thisCtrl.Top) Then
ctrlGoldTop = ctrlTest.Top
Set ctrlGold = ctrlTest
End If
End If
End If
bruteNum = bruteNum + 1
Next ctrlTest
MsgBox (ctrlGold.Name & " is Gold")
End Sub

-end code-

Oh, also, the code is intended to find the nearest control below the
one the function is called in. Thanks in advance for any advice!

__________ Information provenant d'ESET Smart Security, version de la base
des signatures de virus 4596 (20091111) __________

Le message a été vérifié par ESET Smart Security.

part000.txt - le decompactage n'a pas pu etre acheve (motifs possibles
: memoire libre ou espace disque insuffisant, ou probleme avec les
dossiers temporaires)

http://www.eset.com


__________ Information provenant d'ESET Smart Security, version de la base des signatures de virus 4596 (20091111) __________

Le message a été vérifié par ESET Smart Security.

part000.txt - le decompactage n'a pas pu etre acheve (motifs possibles : memoire libre ou espace disque insuffisant, ou probleme avec les dossiers temporaires)

http://www.eset.com
 
D

david couasme

objet de discution de microsft public messagerie windows mail
Eric D. Braden said:
I have written a module with a sub called nearestCtrl which accepts
two arguments. One is as a Form and the other as a Control. My
problem is that both arguments are referring to the same subform. But
each, obviously, refers to a different "state" or object related to
the subform (my VBA understanding begins to break down here). I am
able to just put "Me" in for the form argument, but I have to input
the full path of the subform for the control (like
Me.Parent.f_subSubForm). Is it possible to somehow just put in the
Form argument and somehow load up the Control aspect from within the
function?

So that calling it would just be "nearestCtrl(Me)" instead of
"nearestCtrl(Me, Me.Parent.f_subSubForm)"?


This is the sub:

-code-

Public Sub nearestCtrl(meCtrl As Form, thisCtrl As Control)

Dim ctrlGold As Control
Dim ctrlCurrent As Variant
Dim bruteNum As Long
Dim ctrlTest As Control
Dim ctrlGoldTop As Long

ctrlGoldTop = 100000
For Each ctrlTest In meCtrl.Parent.Controls
If (bruteNum = 0) Then
Set ctrlGold = ctrlTest
Else
If (ctrlTest.ControlType <> acLabel) Then
If (ctrlTest.Top - thisCtrl.Top > 0 And ctrlTest.Top - thisCtrl.Top <
ctrlGoldTop - thisCtrl.Top) Then
ctrlGoldTop = ctrlTest.Top
Set ctrlGold = ctrlTest
End If
End If
End If
bruteNum = bruteNum + 1
Next ctrlTest
MsgBox (ctrlGold.Name & " is Gold")
End Sub

-end code-

Oh, also, the code is intended to find the nearest control below the
one the function is called in. Thanks in advance for any advice!

__________ Information provenant d'ESET Smart Security, version de la base
des signatures de virus 4596 (20091111) __________

Le message a été vérifié par ESET Smart Security.

part000.txt - le decompactage n'a pas pu etre acheve (motifs possibles
: memoire libre ou espace disque insuffisant, ou probleme avec les
dossiers temporaires)

http://www.eset.com


__________ Information provenant d'ESET Smart Security, version de la base
des signatures de virus 4596 (20091111) __________

Le message a été vérifié par ESET Smart Security.

part000.txt - le decompactage n'a pas pu etre acheve (motifs possibles :
memoire libre ou espace disque insuffisant, ou probleme avec les dossiers
temporaires)

http://www.eset.com




__________ Information provenant d'ESET Smart Security, version de la base des signatures de virus 4596 (20091111) __________

Le message a été vérifié par ESET Smart Security.

part000.txt - le decompactage n'a pas pu etre acheve (motifs possibles : memoire libre ou espace disque insuffisant, ou probleme avec les dossiers temporaires)

http://www.eset.com
 

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