473,771 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing form controls from mudules

Bob
Hello:

I have a form with 26 panels. Each panel has a bunch of other controls in
it. The panels visible property are set to False.

Each panel has a corosponding button to set it's visible property to true
and all the other panels to false when clicked.

Well, thats a lot of code in the form. I would like to move the code for the
buttons to a module for code organization.

Here is the code in the form I have for each button.

I tried creating a sub in the module and putting all this in in the sub

Module modPanels
Dim frm1 as Form1
frm1.Label01.Vi sible = True 'Raises an error. Not set to an instance of an
object. As New Form1 causes nothing to happen
frm1.Panel01.Vi sible = True

<Same for other panels> etc
End Module

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Label01.Visible = True
Panel01.Visible = True

Panel02.Visible = False
Label02.Visible = False

Panel03.Visible = False
Label03.Visible = False

Panel04.Visible = False
Label04.Visible = False

Panel05.Visible = False
Label05.Visible = False

Panel06.Visible = False
Label06.Visible = False

Panel07.Visible = False
Label07.Visible = False

Panel08.Visible = False
Label08.Visible = False

Panel09.Visible = False
Label09.Visible = False

Panel10.Visible = False
Label010.Visibl e = False

Me.Panel11.Visi ble = False
Me.Label011.Vis ible = False

Me.Panel12.Visi ble = False
Me.Label012.Vis ible = False

Me.Panel13.Visi ble = False
Me.Label013.Vis ible = False

Me.Panel14.Visi ble = False
Me.Label014.Vis ible = False

Me.Panel15.Visi ble = False
Me.Label015.Vis ible = False

Me.Panel16.Visi ble = False
Me.Label016.Vis ible = False

Me.Panel17.Visi ble = False
Me.Label017.Vis ible = False

Me.Panel18.Visi ble = False
Me.Label018.Vis ible = False

Me.Panel19.Visi ble = False
Me.Label019.Vis ible = False

Me.Panel20.Visi ble = False
Me.Label020.Vis ible = False

Me.Panel21.Visi ble = False
Me.Label021.Vis ible = False

Me.Panel22.Visi ble = False
Me.Label022.Vis ible = False

Me.Panel23.Visi ble = False
Me.Label023.Vis ible = False

Me.Panel24.Visi ble = False
Me.Label024.Vis ible = False

Me.Panel25.Visi ble = False
Me.Label025.Vis ible = False

Me.Panel26.Visi ble = False
Me.Label026.Vis ible = False
End Sub

TIA

Bob
Nov 21 '05 #1
9 1258
Bob wrote:
Hello:

I have a form with 26 panels. Each panel has a bunch of other controls in
it. The panels visible property are set to False.

Each panel has a corosponding button to set it's visible property to true
and all the other panels to false when clicked.

Well, thats a lot of code in the form. I would like to move the code for the
buttons to a module for code organization.

Here is the code in the form I have for each button.

I tried creating a sub in the module and putting all this in in the sub

Module modPanels
Dim frm1 as Form1
frm1.Label01.Vi sible = True 'Raises an error. Not set to an instance of an
object. As New Form1 causes nothing to happen
frm1.Panel01.Vi sible = True

<Same for other panels> etc
End Module

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Label01.Visible = True
Panel01.Visible = True

Panel02.Visible = False
Label02.Visible = False

Panel03.Visible = False
Label03.Visible = False

Panel04.Visible = False
Label04.Visible = False

Panel05.Visible = False
Label05.Visible = False

Panel06.Visible = False
Label06.Visible = False

Panel07.Visible = False
Label07.Visible = False

Panel08.Visible = False
Label08.Visible = False

Panel09.Visible = False
Label09.Visible = False

Panel10.Visible = False
Label010.Visibl e = False

Me.Panel11.Visi ble = False
Me.Label011.Vis ible = False

Me.Panel12.Visi ble = False
Me.Label012.Vis ible = False

Me.Panel13.Visi ble = False
Me.Label013.Vis ible = False

Me.Panel14.Visi ble = False
Me.Label014.Vis ible = False

Me.Panel15.Visi ble = False
Me.Label015.Vis ible = False

Me.Panel16.Visi ble = False
Me.Label016.Vis ible = False

Me.Panel17.Visi ble = False
Me.Label017.Vis ible = False

Me.Panel18.Visi ble = False
Me.Label018.Vis ible = False

Me.Panel19.Visi ble = False
Me.Label019.Vis ible = False

Me.Panel20.Visi ble = False
Me.Label020.Vis ible = False

Me.Panel21.Visi ble = False
Me.Label021.Vis ible = False

Me.Panel22.Visi ble = False
Me.Label022.Vis ible = False

Me.Panel23.Visi ble = False
Me.Label023.Vis ible = False

Me.Panel24.Visi ble = False
Me.Label024.Vis ible = False

Me.Panel25.Visi ble = False
Me.Label025.Vis ible = False

Me.Panel26.Visi ble = False
Me.Label026.Vis ible = False
End Sub

TIA

Bob


You never created an instance of Form1

dim frm1 as new Form1

Otherwise frm1 is just a pointer to nothing.

Chris
Nov 21 '05 #2
Bob
I did

Here is what I tried and nothing happens. Not even an error
Module modPanels
Sub Panel2()
Dim frm1 As New Form1

frm1.Label01.Vi sible = False
frm1.Panel01.Vi sible = False

frm1.Panel02.Vi sible = True
frm1.Label02.Vi sible = True

frm1.Panel03.Vi sible = False
frm1.Label03.Vi sible = False

frm1.Panel04.Vi sible = False
frm1.Label04.Vi sible = False

frm1.Panel05.Vi sible = False
frm1.Label05.Vi sible = False

frm1.Panel06.Vi sible = False
frm1.Label06.Vi sible = False

frm1.Panel07.Vi sible = False
frm1.Label07.Vi sible = False

frm1.Panel08.Vi sible = False
frm1.Label08.Vi sible = False

frm1.Panel09.Vi sible = False
frm1.Label09.Vi sible = False

frm1.Panel10.Vi sible = False
frm1.Label010.V isible = False

frm1.Panel11.Vi sible = False
frm1.Label011.V isible = False

frm1.Panel12.Vi sible = False
frm1.Label012.V isible = False

frm1.Panel13.Vi sible = False
frm1.Label013.V isible = False

frm1.Panel14.Vi sible = False
frm1.Label014.V isible = False

frm1.Panel15.Vi sible = False
frm1.Label015.V isible = False

frm1.Panel16.Vi sible = False
frm1.Label016.V isible = False

frm1.Panel17.Vi sible = False
frm1.Label017.V isible = False

frm1.Panel18.Vi sible = False
frm1.Label018.V isible = False

frm1.Panel19.Vi sible = False
frm1.Label019.V isible = False

frm1.Panel20.Vi sible = False
frm1.Label020.V isible = False

frm1.Panel21.Vi sible = False
frm1.Label021.V isible = False

frm1.Panel22.Vi sible = False
frm1.Label022.V isible = False

frm1.Panel23.Vi sible = False
frm1.Label023.V isible = False

frm1.Panel24.Vi sible = False
frm1.Label024.V isible = False

frm1.Panel25.Vi sible = False
frm1.Label025.V isible = False

frm1.Panel26.Vi sible = False
frm1.Label026.V isible = False
End Sub
End Module
Then in my buttons click event in the Form1

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
modPanels.Panel 2()
End Sub
Nov 21 '05 #3
Bob wrote:
I did

Here is what I tried and nothing happens. Not even an error
Module modPanels
Sub Panel2()
Dim frm1 As New Form1

frm1.Label01.Vi sible = False
frm1.Panel01.Vi sible = False

frm1.Panel02.Vi sible = True
frm1.Label02.Vi sible = True

frm1.Panel03.Vi sible = False
frm1.Label03.Vi sible = False

frm1.Panel04.Vi sible = False
frm1.Label04.Vi sible = False

frm1.Panel05.Vi sible = False
frm1.Label05.Vi sible = False

frm1.Panel06.Vi sible = False
frm1.Label06.Vi sible = False

frm1.Panel07.Vi sible = False
frm1.Label07.Vi sible = False

frm1.Panel08.Vi sible = False
frm1.Label08.Vi sible = False

frm1.Panel09.Vi sible = False
frm1.Label09.Vi sible = False

frm1.Panel10.Vi sible = False
frm1.Label010.V isible = False

frm1.Panel11.Vi sible = False
frm1.Label011.V isible = False

frm1.Panel12.Vi sible = False
frm1.Label012.V isible = False

frm1.Panel13.Vi sible = False
frm1.Label013.V isible = False

frm1.Panel14.Vi sible = False
frm1.Label014.V isible = False

frm1.Panel15.Vi sible = False
frm1.Label015.V isible = False

frm1.Panel16.Vi sible = False
frm1.Label016.V isible = False

frm1.Panel17.Vi sible = False
frm1.Label017.V isible = False

frm1.Panel18.Vi sible = False
frm1.Label018.V isible = False

frm1.Panel19.Vi sible = False
frm1.Label019.V isible = False

frm1.Panel20.Vi sible = False
frm1.Label020.V isible = False

frm1.Panel21.Vi sible = False
frm1.Label021.V isible = False

frm1.Panel22.Vi sible = False
frm1.Label022.V isible = False

frm1.Panel23.Vi sible = False
frm1.Label023.V isible = False

frm1.Panel24.Vi sible = False
frm1.Label024.V isible = False

frm1.Panel25.Vi sible = False
frm1.Label025.V isible = False

frm1.Panel26.Vi sible = False
frm1.Label026.V isible = False
End Sub
End Module
Then in my buttons click event in the Form1

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
modPanels.Panel 2()
End Sub


You never show the form.
Chris
frm.showdialog( )
Nov 21 '05 #4
Bob
Chris:

Form1 is already open. Thats the form that has the button on it. Putting
frm1.showdialog () in the Module opens another Form1

TIA

Bob
Nov 21 '05 #5
"Bob" <Ye*******@nosp am.net> schrieb
Hello:

I have a form with 26 panels. Each panel has a bunch of other
controls in it. The panels visible property are set to False.

Each panel has a corosponding button to set it's visible property to
true and all the other panels to false when clicked.

Well, thats a lot of code in the form. I would like to move the code
for the buttons to a module for code organization.


"Organizati on"? Don't do it as it's often considered bad design. Why don't
you keep it in the Form? If you need the code multiple times, put all
controls onto a usercontrol and place it on as many forms as you need.
Armin

Nov 21 '05 #6
Bob wrote:
Chris:

Form1 is already open. Thats the form that has the button on it. Putting
frm1.showdialog () in the Module opens another Form1

TIA

Bob


Well, you created a new version of Form1, so I assumed you wanted to
show it. If you are trying to access properties on Form1 from the
Module you need to have a reference to the current form....

something like:

Public Sub TestModule(frm1 as Form1)

.... do something on frm1

End Sub

From inside Form1

Private Sub ....
TestModule(me)
End Sub

But my question then becomes why even put this in a module, since you
are acting on frm1, then put the code in frm1, that's why it is a class....

Chris
Nov 21 '05 #7
Bob
Chris:

Thanks. That did it.
But my question then becomes why even put this in a module, since you are
acting on frm1, then put the code in frm1, that's why it is a class....


Yeah someone else said that. I just wanted to break some of that code out of
the form for organization. Is it a performance hit? I'm just using a
standerd module. Not a class mod.

here is the code I wanted to get out of the main form.
http://www.are-hosting.com/panelcode.asp
My skills will improve in time. Maybe when you go to that link, you'll
still think I'm wasting time. Plus it's good experience however trivial it
might be. Gotta start somewhere.

I will be accessing it from other controles later too. There probably is a
better way but if I knew that, I wouldn't be asking for answers to basic
stuff like what you helped me with. I need more experience. I read up on
passing arguments and actually build some functions in VB 6 but that one
eluded me.

Thanks for the help.

Bob
Nov 21 '05 #8
Bob
Armin:

Why not? Chris's tip seems to be working ok. Someday I'll get to the
chapter on user controles. Right now I can only read when I'm on the
toilet. :)

Thanks

Bob
Nov 21 '05 #9
Bob
Armin:

Look at this

http://www.are-hosting.com/panelcode.asp

Bob
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12107
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access those controls from the "calling form", but I am unable to access/see those controls. Why? Here are portions of my code Here I am substantiating the new form and trying to set values for the controls on that form...
1
3139
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created elements and would like to seek a solution for this. I had looked through several articles for accessing programatically-created dynamic elements such as: 1)
6
2253
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as Public, I can access them, but the next time the controls are manipulated in the design mode, they are converted back to Protected. Is there an obvious/easy way around this? Thanks.
3
1346
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount As Integer iCount = pForm.lvJobList.Items.Count
4
3640
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
0
1657
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() RETURNS TABLE AS Begin RETURN
3
10521
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I can get at the value using the array method, the getelements by id method, and the bracket-with-the-element-name in it method. But the dot notation doesn't work, in firefox, in the function (which i have in the head).
8
2183
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
9
1916
by: JohnR | last post by:
I have the name of a control in a string variable and I want to change one of the controls properties. Right now I recursively scan all the controls on the form until I get one whose name matches the name in my string variable, then I know I have the correct control and can proceed to change the property. However all that searching seems like overkill. Does anyone know of a way to directly access the control if it's name is in a string...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.