469,271 Members | 841 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

passing a textbox as argument to a sub

I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(TargetTextbox as textbox)

....

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(me.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel
Nov 13 '05 #1
4 10648
Br
alvb <mi*******@rogers.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(TargetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(me.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel

Maybe try.....

Public Sub FormatTextbox(ByRef pMyTextBox as Control)
'
End Sub

Dim MyControl as Control
Set MyControl = Me![txtMyTextBox]
FormatTextBox MyControl

My question would be why? Why not just pass the value as text and return
it formatted?

eg.

Public Function FormatText(ByVal pText As String) As String

FormatText = Format(">", pText) 'convert to uppercase

End Function

Me![MyTextBox] = FormatText(Me![MyTextBox]

--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #2
In article <KV****************@news-server.bigpond.net.au>,
"Br@dley" <n0****@4u.com> wrote:
alvb <mi*******@rogers.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(TargetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(me.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel


My question would be why? Why not just pass the value as text and return
it formatted?

Actually, it is the textbox itself that I want to format, not the value
of the textbox. I want to alter things like the background color, the
font, font color, etc. All properties that belongs to a textbox.

I can copy over and over the same code for each textbox, but thought
that there must be a cleaner way to do this.

Michel
Nov 13 '05 #3
The two suggestions of declaring your argument ByRef and as Control (not
Textbox) should take care of it. You'll probably still see its .Value
property if you try to evaluate it (e.g. in the Immediate Window), but you
should be able to access properties like ForeColor, BackColor, etc.

HTH

"alvb" <mi*******@REMrogers.com> wrote in message
news:mi*****************************@news.isp.giga news.com...
In article <KV****************@news-server.bigpond.net.au>,
"Br@dley" <n0****@4u.com> wrote:
alvb <mi*******@rogers.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(TargetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the sub

sub a

FormatTextBox(me.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the sub?

Michel


My question would be why? Why not just pass the value as text and return
it formatted?

Actually, it is the textbox itself that I want to format, not the value
of the textbox. I want to alter things like the background color, the
font, font color, etc. All properties that belongs to a textbox.

I can copy over and over the same code for each textbox, but thought
that there must be a cleaner way to do this.

Michel

Nov 13 '05 #4
Br
alvb <mi*******@REMrogers.com> wrote:
In article <KV****************@news-server.bigpond.net.au>,
"Br@dley" <n0****@4u.com> wrote:
alvb <mi*******@rogers.com> wrote:
I want to have a sub that would format my textbox based on the file
status. Since it applies to all textboxes, I would like to do a sub
with a textbox as argument

Like

sub FormatTextbox(TargetTextbox as textbox)

...

End Sub

That part is OK, but I do not know how to pass the textbox to the
sub

sub a

FormatTextBox(me.mytextbox)

end sub

does not work because it sends the default property .value.

What is the proper way to pass the textbox as the argument to the
sub?

Michel


My question would be why? Why not just pass the value as text and
return it formatted?

Actually, it is the textbox itself that I want to format, not the
value of the textbox. I want to alter things like the background
color, the font, font color, etc. All properties that belongs to a
textbox.

I can copy over and over the same code for each textbox, but thought
that there must be a cleaner way to do this.

Michel


Ah missed that:)

The first suggestion (you've snipped it) would havestill helped wouldn't
it?

Public Sub FormatTextbox(ByRef pMyTextBox as Control)
With pMyTextBox
.BackColor = 0
End With
End Sub

Dim MyControl as Control
Set MyControl = Me![txtMyTextBox]
FormatTextBox MyControl
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by mrambil | last post: by
16 posts views Thread by Michael G | last post: by
2 posts views Thread by Rudy Moore | last post: by
1 post views Thread by sofakingfree | last post: by
1 post views Thread by Parasyke | last post: by
5 posts views Thread by Nicholas | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.