Solved

pass values between vb.net forms

Posted on 2011-02-18
2
376 Views
Last Modified: 2012-05-11
I have a form that calls another form.   I can a variable in form2 before calling the showdialog on the form2 and it uses it in code in form 2.  However I would like to pass a value back to the callingform but that seems to be a no go.  I have enclosed the code to call form2 and the code that is supposed to update a variable on form1 before going back to the code.  Please checkout and let me know why myQty variable is 0 when I return from form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myKeyboard As New frmKeyboard
        Dim mQty As Integer = 0

        myKeyboard.mKeyType = 2
        myKeyboard.mItemDesc = Button1.Text
        myKeyboard.ShowDialog()

        FillListBox(Button1.Text, Button1.Tag, myQty)
    End Sub

Open in new window

Private Sub cmdEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnter.Click
        FrmInspection.myQty = CInt(txtQty.Text)
        Me.Close()

    End Sub

Open in new window

0
Comment
Question by:mgmhicks
2 Comments
 
LVL 12

Expert Comment

by:omegaomega
ID: 34928779
Hello, mgmhicks,

Where are you declaring and setting FrmInspection?

Cheers,
Randy
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34928791
In FrmInspection, use your "myKeyboard" variable to access the txtQty box on your dialog:
If myKeyboard.ShowDialog() = DialogResult.OK Then
    Me.myQty = CInt(myKeyboard.txtQty.Text)
    FillListBox(Button1.Text, Button1.Tag, Me.myQty)
End If

Open in new window


In myKeyboard, set DialogResult instead of using Close():
Private Sub cmdEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEnter.Click
        Me.DialogResult = DialogResult.OK
    End Sub

Open in new window

0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question