Problem with Form Refresh

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi , I am having problems refreshing my main form after performing a search. I have two variables in my search form that get passed into my sql statement. I put some stops in my code and see that my variables are getting passed into my GetData() sub routine, but my main form is not refreshing. I have not adjusted my search form to hide yet, and Im just trying to get the main form to refresh at this point. Any help appreciated. Here is my code:This is my search form:
Public Class Search

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

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

With frmMenu
.SearchField = ChangeField
.mySearchString = txtSearch.Text
.GetData()
End With

End Sub
End Class

This is my main form:
Public Class frmMenu
Public mySearchString As String
Public 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, ADDR1, ADDR2, ADDR3, WORK, NOTES, LOAN_NUM, DEALERNO, ATTY_PER, INT_RATE, PHONEW, PHONEH, PHONEO, STATUS, CLIENT, ACCR_FEE, CODE, DATE, AMT, LST_PMTA, TOTAL_PMT, ACCR_COST, ACCR_INT, TOTAL_INT, LST_PMTD, LST_TRAN 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()

Clear Financial Tab Controls
fIRPercent.DataBindings.Clear()
fAttyPercent.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")

txtAddr1.DataBindings.Add("Text", masterBindingSource, "ADDR1")
txtAddr2.DataBindings.Add("Text", masterBindingSource, "ADDR2")
txtAddr3.DataBindings.Add("Text", masterBindingSource, "ADDR3")
txtWork1.DataBindings.Add("Text", masterBindingSource, "WORK")


Financials Tab Controls
fIRPercent.DataBindings.Add("Text", masterBindingSource, "INT_RATE")
Ftype.DataBindings.Add("Text", masterBindingSource, "CODE")

Catch ex As OleDb.OleDbException
MessageBox.Show("Learn to code n00b! " & _
"check SQL " & _
"check syntax.")
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)

detailsDataGridView.DataSource = detailsBindingSource

SearchField = "Name1"

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

View the full article
 
Back
Top