472,342 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 10989
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: mrambil | last post by:
Hi, I'm using PHP 4.3.3 in CLI on Win XP SP1. I use the _experimental_ w32api. It seems to work quite fine yet I cannot pass a string argument to...
16
by: Michael G | last post by:
I have an api that uses reference as arguments. void function(double z, short &x, short &y){} some calculations are done on z and then the...
2
by: Rudy Moore | last post by:
Is this valid c++? f()'s argument is a reference, but has a default value. It compiles with gcc 3.3.3 class A {}; void f(const A& a = A())...
3
by: Scott | last post by:
What is the proper syntax for sending an argument from a form contol to a subroutine in a module? For instance, from a textbox on a form I call a...
1
by: sofakingfree | last post by:
I keep getting an invalid property assignment error when tring to reference a subform. All I am trying to do is substitute this: ...
1
by: Parasyke | last post by:
Please forgive this newbie, but can someone help with what is sure to be simple for the veterans of VB.net: I have a form with TextBox1 and a...
5
by: Nicholas | last post by:
Hello, i need to pass an argument to window.open but it seems it wont work. What am i doing wrong? This in in head: <SCRIPT...
2
by: ruk | last post by:
Hi all, I have craeated a windows service in C# which monitors the user's request to the server. It should display the username and the...
1
by: KayC | last post by:
Hi I am using Access2002 I have a form with 5 text boxes which are parameters to a function 3 parameters are optional in the function How do I...
1
by: tina2626 | last post by:
how can i pass textbox value to gridview using C#.net at runtime not using database values. i m hving textbox1 and gridview1. can anyone...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.