Solved

pass values between vb.net forms

Posted on 2011-02-18
2
358 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now