|
-
Nov 11th, 2008, 10:13 AM
#1
Thread Starter
New Member
[RESOLVED] using fields from Form1 no longer works ?
I have a multi-form Windows Mobile 6 app where the initial form (Startup object ) is called Form1.
On Form1 I complete a few combo boxes - user Name - Sales area - Date etc
From there I use Radio buttons to load other forms ... and it all worked fine
BUT ....
I decided to put a pretty new form on the front - use that as the Startup object - and from that load Form1 - and then process as before.
The other forms can no longer pick up the fields from Form1 !!!
I use a simple format on (say) Form2 ........
Code:
me.tbUsername.text = Form1.cbUsername.text
and it worked fine - but now doesn't !!
Unless I reset Form1 as my Startup object .. and then it is a happy bunny again ??
Is this a known problem please ?
PS I tried changing the code to use a return call ..
Code:
Public Function showDistrict() As String
Return Me.cbDistrict.Text
End Function
with an appropriate ...
Code:
Me.tbDistrict.Text = Form1.showDistrict()
on form2
it did not help ?
-
Nov 11th, 2008, 10:20 AM
#2
Fanatic Member
-
Nov 11th, 2008, 10:43 AM
#3
Re: using fields from Form1 no longer works ?
Stop using default form instances....
When you do this in Form2
Code:
me.tbUsername.text = Form1.cbUsername.text
A default instance of Form1 is created, and that instance is not the same instance of Form1 that you already have, thus you don't get the data expected.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Nov 11th, 2008, 11:17 AM
#4
Thread Starter
New Member
Re: using fields from Form1 no longer works ?
Thanks for that Stanav ....
That makes sense .... so how should I have done it please ?
(I wonder why it worked previously ?)
-
Nov 11th, 2008, 11:39 AM
#5
Re: using fields from Form1 no longer works ?
You need to somehow pass a reference of the instance of Form1 you have to the other form. This can be done by creating a property in the other form and set it when you create a new instance. something like this
Code:
'This is in form1, when you are about to show form2
Dim frm2 As New Form2()
frm2.FormRef = Me '<<< You're passing a reference of this Form1 instance to Form2 here
frm2.Show()
====================================================
'Then in Form2, you declare a property called FormRef
Private _FormRef As Form1 = Nothing
Public Property FormRef() As Form1
Get
Return _FormRef
End Get
Set (ByVal value As Form1)
_FormRef = value
End Set
End Property
'And then when you want to get some value from Form1, you do
Dim frm1 As Form1 = Me.FormRef
If frm1 IsNot Nothing Then
Me.tbDistrict.Text = frm1.showDistrict()
End If
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Nov 11th, 2008, 11:43 AM
#6
Thread Starter
New Member
Re: using fields from Form1 no longer works ?
Many thanks for that Stanav -
I will try that now and let you know how I get on ..
Your patience is very much appreciated
-
Nov 11th, 2008, 12:02 PM
#7
Thread Starter
New Member
Re: using fields from Form1 no longer works ?
The great news is that it workd perfectly - so many thanks for that ..
The quite good news is that I actually understand about half of it ... so can spend some quality time learning the rest :-)
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
|