Assigning variable to a TextBox

V

VBeejit

Can someone please give me the correct & full syntax
for 'Dim'ing a variable & then assigning it to a Textbox &
then referring to it to alter properties eg. tabstop, font
etc.

thanks.
 
J

Jonathan Parminter

-----Original Message-----
Can someone please give me the correct & full syntax
for 'Dim'ing a variable & then assigning it to a Textbox &
then referring to it to alter properties eg. tabstop, font
etc.

thanks.
.
Hi ViBeetjit, you can work directly with a control to
change the properties of a control. for example,

with txtThing
..tabstop=true
..backstyle=1
end with

However, to dim a variable explicitly for a textbox...
dim txt as textbox
or loosely...
dim ctl as control

then use the first example to read or set a value.

Luck
Jonathan
 
V

VBeejit

I can't get the right syntax for setting the dimmed
variable txtData to an existing TextBox. I have 2
different textboxes, myText1 & myText2, only one of which
is ever visible and I have comboboxes and command buttons
to change the alignment, font, fontsize etc and I don't
want to have to duplicate the same code twice for 2
different TextBoxes, instead I'm trying to set a variable
txtAd to either myText1 or myText2 and then have one set
of controls changing font & so on.
eg; Me.txtAd(Variable).Font = Me![combo1]
Me.txtAd.ForeColor = dblAdColor - another variable set
from a long(ish) Select Case statement linked to another
ComboBox.

hope that clarifies rather than confuses issues further.

VBeejit
 
V

VBeejit

-----Original Message-----
Can someone please give me the correct & full syntax
for 'Dim'ing a variable & then assigning it to a Textbox &
then referring to it to alter properties eg. tabstop, font
etc.

thanks.
.
 
J

John Vinson

We'd be glad to answer your question if we could understand what
you're asking.

Literal answer:

Dim strX As String ' Dim a variable as a String
strX = "This Is A String" ' assign it a value
Me!txtTextboxA = strX ' assign that value to a textbox

But "referring to it" is ambiguous; referring to WHAT?
 
D

Dirk Goldgar

I think what you're looking for could be done in either of two ways:

(1) A Control Variable

Dim txtTheBox As Textbox

Set txtTheBox = Me!MyText1 ' ... or Me!MyText2

With txtTheBox
.TabStop = True
.FontName = "Arial"
.FontBold = True
End With

Set txtTheBox = Nothing

(2) A String Index Into the Controls Collection

Dim strTheBox As String

strTheBox = "MyText1" ' ... or "MyText2"

With Me.Controls(strTheBox)
.TabStop = True
.FontName = "Arial"
.FontBold = True
End With
 

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