set properties of a passed textbox name

B

Ben8765

Hi,

I'd like to pass the name of a textbox to a procedure, and then set that
textbox to be locked.

Reason: I want to set many textboxs' properties to locked (and later other
properties).

This is what I have so far:

Private Sub Status_RS_Initiated_AfterUpdate()
Call Textbox_Effects("RS_Initiated")
End Sub

Public Sub Textbox_Effects(TextBox_Name)
TextBox_Name.Locked = False
End Sub

Problem: 'TextBox_Name.Locked = False' returs error: 'Object Required'

I can take awa the quotes from "RS_Initiated", but then that just passes the
value of the text box. I want to pass the name.

Any ideas?
 
D

Douglas J. Steele

Private Sub Status_RS_Initiated_AfterUpdate()
Call Textbox_Effects(Me.Controls("RS_Initiated"))
End Sub

Public Sub Textbox_Effects(TextBox As Control)
TextBox.Locked = False
End Sub
 
J

Jack Leach

You can do this by passing the textbox object itself, or by passing the name
of the textbox...

if you want to pass the name....

Public Sub UnLockControl(sControlName As String)
Me.Controls(sControlName).Locked = False
End Sub


and call it like so...

UnLockControl Me.Textbox.Name


or, if you want to pass the control itself....

Public Sub UnLockControl(ctl As Control)
ctl.Locked = False
End Sub

and call it like so...

UnLockControl Me.Textbox




This assumes that the public sub is in the form's module... however, you can
globalize this function rather easily....

Public Function fLockControl( _
frm As Form, _
ctl As Control, _
bLock As Boolean)

frm.Controls(ctl.Name).Locked = bLock

End Function

and call if from any form by....

fLockControl Me, Me.Textbox, False




The thing to notice here is that while the value of a control is often
referenced by using Me.Controlname, in fact that actually passes the control
itself... Access assumes that you meant Me.Controlname.Value when you try to
assign this to a standard datatype variable. But if the datatype of a
variable is an Object or Control then Me.Controlname will be passed as the
control itself, in which case you can do anything with it that you would in
your normal form procedure....

?ctl.Name
?ctl.Visible
?ctl.Enabled

etc etc


hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 

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