Results 1 to 7 of 7

Thread: [RESOLVED] using fields from Form1 no longer works ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    South Wales, UK
    Posts
    14

    Resolved [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 ?

  2. #2
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: using fields from Form1 no longer works ?

    On my mobile apps, I use a module to keep track of data between forms. Just makes it easier to update plus it will stay there as long as the program runs. Maybe you could try the same?

    HTH,

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    South Wales, UK
    Posts
    14

    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 ?)

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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 -

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    South Wales, UK
    Posts
    14

    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    South Wales, UK
    Posts
    14

    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
  •  



Click Here to Expand Forum to Full Width