Link to home
Start Free TrialLog in
Avatar of ingenito
ingenitoFlag for United States of America

asked on

Values in other forms?

Hello,

   I have a program that is not MDI.  I have two forms one called frmMain and one called frmBrowser.  For some reason I can't access values in frmMain from frmBrowser.  For example, on frmMain there are 3 text boxes and 1 list box.  If I try to access the values of these from frmBrowser it doesn't work.  For example, frmMain.txtUsername is blank when I use it in frmBrowser.  If I select the first item in the listbox, frmMain.lstItems.selected(0) is false.  But the weird thing is I can access the properties.  I can get the values like frmMain.txtUsername.height and frmMain.lstItems.listcount.  Whats going on here, do the forms need to be MDI childs to be able to access each others values?

Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

They don't need to be MDI children, but they do need to be loaded at the same time. Otherwise attempting to get the value of a control on another form will Load the other form implicitly (may not show it unless you specify this) and you will then get the default value of each control.
Avatar of gencross
gencross

I have tried a simple test of this myself and it seems to work fine.  Is there any other info you could provide?

You do not need to use MDI to do this.  It should work fine.
I assume both of your forms are loaded?
Avatar of ingenito

ASKER

Yes, frmMain loads first, then frmMain calls frmBrowser and frmBrowser is trying to get data from frmMain.
Ok,

I just did a simple test by creating a new project and it works fine.  The application I'm having trouble with was created with the wizard.  Could this have anything to do with it?

ASKER CERTIFIED SOLUTION
Avatar of ebosscher
ebosscher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
did you unLoad the frmMain when opening frmBrowser?
if so, change the statement "Unload Me" to "Me.Hide".
also, use "frmMain.txtUsername.Text" (notice the ".Text").

if it still cannot work, declare a public variable in frmMain. (this is what ebosscher suggest)

//put this in Declaration section
Public UserName as String

//put this under subroutine that open your frmBrowser
UserName=txtUserName.Text
frmBrowser.Show

//use the UserName, instead of txtUserName
//in your frmBrowser, eg.
Msgbox frmMain.UserName
Avatar of DanRollins
Hi ingenito,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

ingenito, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer