|
-
Aug 13th, 2002, 10:20 AM
#1
Thread Starter
Junior Member
Accessing Form Controls via a sub
Does anyone know how to access a windows form control e.g. a text box from a sub procedure within a module. For example, I would like to call a sub in the form load event to prefill a text box or a listbox. However, I cannot access the active form's controls.
-
Aug 13th, 2002, 08:00 PM
#2
New Member
Use Form Activate event. Controls may not be available when the load event fires.
-
Aug 13th, 2002, 08:26 PM
#3
Thread Starter
Junior Member
solution
Passing the form control to the sub works as others had suggested in other posts.
'Form 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call mySub(Me.TextBox1)
End Sub
'Module 1
Module Module1
Public Sub mySub(ByRef mytextBox As TextBox)
mytextBox.Text = "test"
End Sub
End Module
-
Aug 13th, 2002, 08:27 PM
#4
Originally posted by Teacher
Use Form Activate event. Controls may not be available when the load event fires.
I believe controls are accesible after the Form.New is done, so it should be available in Form_Load (I THINK!)
I'm not sure what exactly you want to do... you say you want to access the control through a module? or you want to access it in Form_Load?!
umm and if you want to prefill some controls when you load the form, you could just modify the New constructor to receive the controls....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|