none
How to open and save the same form multiple times without closing the form until the last entry. RRS feed

  • Question

  • I have a routine that opens a fees form and allows the user to input a fee and save and close the form when OK is clicked.  That routine has a If showdialog.ok in it which prevents opening a new instance of the fees form once OK is clicked on the fees form.  What I'd like to do is after the fees form is initially opened, be able to enter the first fee and click a button that saves the current data and that re-opens a new fees form or re-initializes the same form to enter multiple fees at a time before the OK button is clicked.  Can anyone offer some sample code on how to do this?  Any help would be appreciated.  Thanks.
    Sunday, September 8, 2019 5:56 PM

All replies

  • Hi

    It sounds like it is a straightforward task.

    *

    On the 'fee' Form , when User clicks the button, just do the save and then clear the User input(s) ready for next fee.You might want to consider a second button, the first for 'new'fee entry which saves/clears data, and second to exit the Form back to the first Form.


    Regards Les, Livingston, Scotland

    Sunday, September 8, 2019 6:21 PM
  • Hi

    Here is an example of one way. Form1 and Form2

    Form1

    Option Strict On
    Option Explicit On
    Public Class Form1
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		' remove Hide/Show if you want 
    		' Form1 to remains shown
    		Dim f2 As New Form2
    		Hide()
    		f2.ShowDialog()
    		Show()
    	End Sub
    End Class

    Form2

    Option Strict On
    Option Explicit On
    Public Class Form2
    	Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    		TextBox1.Text = Nothing
    	End Sub
    	Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    		SaveData()
    	End Sub
    	Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    		Dispose()
    	End Sub
    	Sub SaveData()
    		' perform save here
    	End Sub
    End Class


    Regards Les, Livingston, Scotland






    • Edited by leshay Sunday, September 8, 2019 7:11 PM
    Sunday, September 8, 2019 6:34 PM
  • Hi,

    Form1:

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Form2.Show()
        End Sub

    put two Buttons in Form2, one to save the changes, one to save the changes

     Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
            Me.Hide()
        End Sub
    
        Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
            Me.Close()
        End Sub

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 9, 2019 8:42 AM
    Moderator