Home All Groups Group Topic Archive Search About

Set textbox1.enabled = false inside a module?

Author
6 Apr 2005 1:29 PM
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.

Author
6 Apr 2005 1:31 PM
Daniel
try this in the module:

sub disabletextbox
    dim myform as new form1
    myform.textbox1.enabled = false
end sub

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.

Show quoteHide quote
"David Eadie" <hack***@hotmail.com> wrote in message
news:da1009c8.0504060529.35d7a284@posting.google.com...
> 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.
Author
6 Apr 2005 1:57 PM
Chris Dunaway
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
Author
6 Apr 2005 9:17 PM
hack123
Holy Wow!! Great replies from both. (I was looking at both of the
problems identified Daniel and Chris.)

Many thanks!!

Dave. :-)
Author
7 Apr 2005 7:57 AM
Daniel
Doh!  Hadn't had my Ready Brek by then.  I was looking at it backwards.
Sorry.    :-(

--

Daniel
MCSE, MCP+I, MCP in Windows 2000/NT

--------------------------------------
remove the 2nd madrid from my mail address to contact me.

Show quoteHide quote
"Chris Dunaway" <dunaw***@gmail.com> wrote in message
news:1112795820.797298.83020@l41g2000cwc.googlegroups.com...
> 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
>