assigning a control to a variable question

D

djc

if I dim a variable to hold a control how can I assign a particular control
to it? what are my options.

I have a var like so:

dim ctl as control

I want to assign a text box to it based on the name of the text box. can I
do this? I get a type mismatch error when trying but I am also concatenating
to get the text box name. Like this:

dim x as integer
dim str as string
' values get assigned elsewhere

set ctl = str & CStr(x)

Thats when I get the type mismatch error.

anyone?
 
A

Allen Browne

Use a string variable to access a member of the Controls collection of the
form:
Dim strControlName As String
Dim ctl As Control
strControlName = "SomeText" & Cstr(X)
set ctl = Me(strControlName)
 
P

PC Datasheet

If you want to assign a specific control to the variable Ctl, why not just use
Me!NameOfYourTextbox?

To answer your question, use
dim ctl as control
Set Ctl = Me.Controls("NameOfTextbox")
 

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