Results 1 to 7 of 7

Thread: multi forms - form1 not reloading

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    21

    Thumbs up multi forms - form1 not reloading

    Hi I am using two forms.
    Form 1 organizes student information from a textfile
    Form 2 appends a new student

    I load the second form with:
    Code:
    Dim secondForm As New Form2
            secondForm.ShowDialog()
    It loads, cool..
    When I close form 2 with me.close, form 1 does not have the updated information. (Most things load with the form_load event)

    Any ideas? This is form my intro to VB course. Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: multi forms - form1 not reloading

    The data won't just appear in Form1. You have to write code to get it form somewhere and display it. Assuming that Form2 saves the data then the simplest option is to simply move the code that loads the data out of the Load event handler and into its own method. You can then call that method from the Load event handler and any other time it's needed too.

    A better option, in my opinion, is for Form2 not to save the data. Once Form2 is dismissed, Form1 retrieves all the new data from Form2 via properties that you have declared. Form1 will then add that data to the data its displaying and then Form1 will save the changes. That way Form1 is responsible for all data management and Form2 is just a data entry form.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    21

    Re: multi forms - form1 not reloading

    jmcilhinney--I entirely agree with you about the second point, that I should store all the info using Form 1. Unfortunately I do not think I have enough time to recode it...This is my first experience with multi forms.

    What code would allow me to reload it? edit: (... I have no idea how to do what you said)
    Last edited by crabramson; Apr 27th, 2009 at 11:56 PM. Reason: edit

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: multi forms - form1 not reloading

    Quote Originally Posted by crabramson View Post
    I have no idea how to do what you said)
    Yes you do because you've done it before, more than once I'm sure. You've declared a Sub before, yes? You've called a Sub before, yes? That's all you've got to do now. Declare a Sub and take the code that loads the data out of the Load event handler and put it in that new Sub. You then call that new Sub in the Load event handler and everything will happen as it did before. Now, though, you can call that same Sub from other places too, whenever you need to load data. You need to load data after your second form is dismissed so you just call your Sub at that point.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    21

    Re: multi forms - form1 not reloading

    thank you very much sir
    it works great now

    in the future it would be more helpful if you gave examples of code, but nonetheless you're very helpful indeed

    one problem i faced:
    it was doubling null fields in the listbox when I generated the student report so i added an if statement to check for null before output

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: multi forms - form1 not reloading

    Quote Originally Posted by crabramson View Post
    in the future it would be more helpful if you gave examples of code
    That depends on your definition of helpful. It might make it easier for you if I provided the code for you but I don't post here to make it easy for people. I post to help people become better developers and I find that the best way to do that is to push people to think for themselves because that's how you learn. As has been born out by the result, you actually did already know how to solve your own problem so you didn't need me to write the code for you. If I can make people think first and ask questions later instead of having other people do their thinking for them as a first option then I've been as helpful as I possibly can. You'll thank me in years to come.
    Last edited by jmcilhinney; Apr 28th, 2009 at 09:29 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: multi forms - form1 not reloading

    Just out of curiosity, what code could JM have provided that would have been any help? What he described was to add a sub and copy and paste existing code. I'm kind of curious as to what a meaningful code example would look like? If you meant an example of using properties, there is one that I could post a link for, but I don't think there was all that much code in that thread, either, as there is very little 'example' possible.
    My usual boring signature: Nothing

Tags for this Thread

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