473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 11157
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 any of my dll functions : 1) Load the w32api...
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 results are being passed back out in x and y. 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()) {} int main() { f(); return 0;
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 module subroutine from the textbox's OnUpdate...
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: Forms!!.SetFocus for this: FormAndSubForm.SetFocus
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 button, Button1. I need to pass the value of the...
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 LANGUAGE="JavaScript"> <!-- function nw(a,b){ myWindow =...
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 Loggeddatetime of the user who all are loggedin to the server...
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 pass the empty textbox values to a optional...
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 suggest me to do this coding in ASP.NET(C# language).
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.