Me. Noob question...just wanting to be sure...

1jet

Registered User.
Local time
Tomorrow, 01:07
Joined
Sep 15, 2008
Messages
117
Hi all,

I've learnt two different ways from this forum to get a value from a text box.

Code:
dim txtBox as control
dim strTxtBox as string

set txtBox = Forms("frmFormName").Controls("txtBoxName")

strTxtBox = txtBox.value

...and...

Code:
dim strTxtBox as string

strTxtBox = me.txtBoxName.value

obviously the latter is must shorter...but is there any downside to it?
 
Noob,

Since "Value" is the default property of a textbox control, your second VBA statement can be made even shorter to:

strTxtBox = Me.txtBoxName

Ken
 
Code:
dim txtBox as control
dim strTxtBox as string

set txtBox = Forms("frmFormName").Controls("txtBoxName")

strTxtBox = txtBox.value

This could equally be written as:
Forms.frmFormName.textBoxName

The only difference being you are using txtBox as a variable (for the control).

You can use the above method to reference any control on any form that is open.


Code:
dim strTxtBox as string

strTxtBox = me.txtBoxName.value

When you use me. you can only reference controls on the form that has the focus.

My understanding is me. is better to use where possible because it is faster. However, if you are trying to reference a control other than the one that has the focus then you must use the full reference.

hth
Chris
 

Users who are viewing this thread

Back
Top Bottom