Solved

pass values between vb.net forms

Posted on 2011-02-18
2
344 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
Comment Utility
Hello, mgmhicks,

Where are you declaring and setting FrmInspection?

Cheers,
Randy
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 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

11 Experts available now in Live!

Get 1:1 Help Now