ReportsNerd
Active member
- Joined
- Nov 24, 2012
- Messages
- 31
- Programming Experience
- 3-5
Hi, I need to expand the search capabilities of my app. Right now, I'm using an input box to collect name search criteria. But now, I need to be able to search on Name1, Name2 and customer number. Should I use a modal form instead in order to have more control or can I still use an input box like the code below?
I also need the capability to move next and back in the record set. So after a search on Name1, I need to be able to click the Next button and navigate to the next match in the record set. Note my Select statement is ordered.
Help/suggestions appreciated. Thanks
I also need the capability to move next and back in the record set. So after a search on Name1, I need to be able to click the Next button and navigate to the next match in the record set. Note my Select statement is ordered.
Help/suggestions appreciated. Thanks
VB.NET:
Public Class Menu
Dim mySearchString As String
Dim mySelectionString As String = "SELECT * FROM DEBTOR WHERE NAME1 like '" & mySearchString & "%' ORDER By NAME1"
Dim myDataSet As New DataSet
Dim daDebtors As OleDb.OleDbDataAdapter
Dim TheCorrectRowIndexOfTheTable_BasedOnTheSearchCriteria As Integer
Dim TotalRowsInDataTable As Integer
Private Sub Menu_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim myConnectionString As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & Application.StartupPath & "\TestDB1.accdb'")
myConnectionString.Open()
daDebtors = New OleDb.OleDbDataAdapter(mySelectionString, myConnectionString)
TotalRowsInDataTable = daDebtors.Fill(myDataSet, "Debtors")
End Sub
Private Sub BtnSeek_Click(sender As System.Object, e As System.EventArgs) Handles BtnSeek.Click
mySearchString = InputBox("Name:", "Search", "Anderson")
Dim CurrentTableRowNumber As Integer
Dim found As Boolean = False
For CurrentTableRowNumber = 0 To TotalRowsInDataTable - 1
If myDataSet.Tables("Debtors").Rows(CurrentTableRowNumber).Item(2).ToString.ToLower.StartsWith(mySearchString.ToString.ToLower) Then
TheCorrectRowIndexOfTheTable_BasedOnTheSearchCriteria = CurrentTableRowNumber
DisplaySearchResults()
found = True
Exit For
End If
Next
If Not found Then
MsgBox("Search Not Found")
End If
End Sub
Private Sub DisplaySearchResults()
'Main Tab Controls
txtName1.Text = myDataSet.Tables("Debtors").Rows(TheCorrectRowIndexOfTheTable_BasedOnTheSearchCriteria).Item(2).ToString
txtName2.Text = myDataSet.Tables("Debtors").Rows(TheCorrectRowIndexOfTheTable_BasedOnTheSearchCriteria).Item(3).ToString