ReportsNerd
Active member
- Joined
- Nov 24, 2012
- Messages
- 31
- Programming Experience
- 3-5
Hello, I am having trouble with a refresh on my main form. When I put a stop in my main form, it appears that my search variables are being sent correctly by the Search form's Button1_Click, but the main form is not being refreshed. Help appreciated. Here is my code so far:
VB.NET:
Public Class Menu
Public Shared mySearchString As String
Public Shared SearchField As String
'Create variables for Master/Detail
Private masterBindingSource As New BindingSource()
Private detailsBindingSource As New BindingSource()
Public Sub GetData()
Try
' Specify a connection string:
Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & Application.StartupPath & "\TestDB1.accdb'"
Dim connection As New OleDb.OleDbConnection(connectionString)
' Create a DataSet.
Dim data As New DataSet()
data.Locale = System.Globalization.CultureInfo.InvariantCulture
' Add data from the Debtor table to the DataSet.
Dim masterDataAdapter As _
New OleDb.OleDbDataAdapter("select FILE_NO, NAME1, NAME2 from Debtor Where " & SearchField & " Like '" & mySearchString & "%'", connection)
masterDataAdapter.Fill(data, "Debtor")
' Add data from the Transactions table to the DataSet.
Dim detailsDataAdapter As _
New OleDb.OleDbDataAdapter("select FILE_NO, DATE, CODE, AMT, BAL, NOTES from TRANS ORDER By DATE DESC, CODE DESC", connection)
detailsDataAdapter.Fill(data, "Trans")
' Establish a relationship between the two tables.
Dim relation As New DataRelation("DebtorTrans", _
data.Tables("Debtor").Columns("FILE_NO"), _
data.Tables("Trans").Columns("FILE_NO"), False)
data.Relations.Add(relation)
' Bind the master data connector to the Debtor table.
masterBindingSource.DataSource = data
masterBindingSource.DataMember = "Debtor"
' Bind the details data connector to the master data connector using the DataRelation name to filter the information in the
' details table based on the current row in the master table.
detailsBindingSource.DataSource = masterBindingSource
detailsBindingSource.DataMember = "DebtorTrans"
'Clear Main Tab Controls
txtFileNo.DataBindings.Clear()
txtName1.DataBindings.Clear()
txtName2.DataBindings.Clear()
'Populate Main Tab controls
txtFileNo.DataBindings.Add("Text", masterBindingSource, "FILE_NO")
txtName1.DataBindings.Add("Text", masterBindingSource, "NAME1")
txtName2.DataBindings.Add("Text", masterBindingSource, "NAME2")
Catch ex As OleDb.OleDbException
MessageBox.Show("I must have messed up " & _
"bad!.")
End Try
End Sub
Private Sub Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.DEBTORTableAdapter.Fill(Me.DTdataset.DEBTOR)
' Bind the controls to the BindingSource components and load the data from the database.
detailsDataGridView.DataSource = detailsBindingSource
GetData()
detailsDataGridView.AutoSizeColumnsMode = _
DataGridViewAutoSizeColumnsMode.AllCells
End Sub
Private Sub BtnSeek_Click(sender As System.Object, e As System.EventArgs) Handles BtnSeek.Click
Dim ShowSearch As New Search()
ShowSearch.Show()
End Sub
'This is my search form. I want to collect the values entered on this form and pass it back to the query on my main form:
Public Class Search
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Menu As New Menu()
Dim ChangeField As String = "Name1"
If optName1.Checked Then
ChangeField = "Name1"
ElseIf optName2.Checked Then
ChangeField = "Name2"
ElseIf optSSN.Checked Then
ChangeField = "SSN"
End If
Menu.SearchField = ChangeField
Menu.mySearchString = txtSearch.Text
Menu.GetData()
End Sub
End Class