Set textbox1.enabled = false inside a module?

  • Thread starter Thread starter David Eadie
  • Start date Start date
D

David Eadie

G'Day all,

Ok I have form1 and lets say it has a textbox on it called
textbox1.text.

Now in that form1_load sub I have a command that says:

my_custom_set_txt_box_properties.disabletextbox.

Now I have a module called my_custom_set_txt_box_properties and in
that module I have a sub that follows:

sub disabletextbox
textbox1.enabled = false
end sub

Why cant I call that module in the form1_load sub and get it to
disable the textbox?
I am somewhat new to module's at this stage and would greatly
appreciate any help. (And keep you posted on my results ;-) )
Thanks All

Dave.
 
try this in the module:

sub disabletextbox
dim myform as new form1
myform.textbox1.enabled = false
end sub
 
That will just create a new Form1 and not change the textbox on the
existing Form1.

A form is an object just as any other. In order to change the
properties of an object, you must have a reference to that object.

Inside your module sub, you say:

textbox1.enabled = false

Which textbox are you trying to disable? What if you had two forms
each with a textbox called textbox1? How would that sub know which
textbox to disable?

It would be better to write the sub to take a textbox as an argument:

Module MyModule
Public Sub DisableTextBox(tb As TextBox)
tb.Enabled = False
End Sub
End Module

Then in your form load:

MyModule.DisableTextBox(Me.TextBox1)

If you need to manipulate other controls and properties of the form,
you might wish to make a global variable in your module to hold a
reference to your form and then in the form load, assign that variable:

Module MyModule
Public MyFormRef As Form1

End Module

Then in Form Load:

MyModule.MyFormRef = Me


That way any sub in the module has access to the form and it's
properties and controls.

Chris
 
Holy Wow!! Great replies from both. (I was looking at both of the
problems identified Daniel and Chris.)

Many thanks!!

Dave. :-)
 
Back
Top