I have an VB .NET application in which I need to collect some range data prior to searching a database for a report. I have tried the examples given in this forum, to no avail. What I cannot seem to get straight is how to get the data and key-press data from the second form back to the first.
When the user presses a menu button I want to show a small form(form2) whereiin the user enters the search keys, then presses an "Ok" button. When the Ok button is pressed I want the key data available to the application(form1) and the form2 to disappear. The user will also be able to press a "cancel" button on form2 wherein the application(form1) will be able to so note.
I've looked here and elsewhere and tried dozens of approaches, all have failed on one way or another. In the code below I've stripped my attempts and left the basic code in hopes someone can help in what should be a simple problem. I will surely appreciate any help offered.
Here is what i've done...
Created Form2 with two text boxes and two buttons. I'd put the graphics here but I don't know how.
In form2
VB Code:
Public Class Form2 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " #End Region Public BookNumberLow As Integer Public BookNumberHigh As Integer Public GetKeyStatus As Boolean Public Sub main() End Sub Private Sub Ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ok.Click BookNumberLow = Int(BookNumberLowBox.Text) BookNumberHigh = Int(BookNumberHighBox.Text) If BookNumberLow > BookNumberHigh Then MessageBox.Show("Starting Book Number must not be greater than Ending Book Number", "Error", MessageBoxButtons.OK) Else GetKeyStatus = True End If End Sub Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click GetKeyStatus = False End Sub Public Property Status() As Boolean Get Return GetKeyStatus End Get Set(ByVal Value As Boolean) GetKeyStatus = Value End Set End Property Public Property Hi() As Integer Get Return BookNumberHighBox.Text End Get Set(ByVal Value As Integer) BookNumberHighBox.Text = Value End Set End Property Public Property Low() As Integer Get Return BookNumberLowBox.Text End Get Set(ByVal Value As Integer) BookNumberLowBox.Text = Value End Set End Property End Class
in form1
VB Code:
Private Sub MenuItem21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem21.Click Dim GetKeys As New Form2 GetKeys.ShowDialog(Me) ' 'Code to get the key pressed in form2 and the low and high keys ' Call PrintByTitle() End Sub




Reply With Quote