I have created an ADO database (VB6).
Everything is working fine, but I need to add a Search Button, to search for existing records, and then to display (move to ) the relevant record using the same database.
Attached please find the code I am using, but it has faults ??
Private Sub cmdSearch_Click()
'The % means all Records that starts with example an A must be Find.
datPrimaryRS.Recordset.Close
datPrimaryRS.Recordset.Source = "Select * from [HRM] where Persal No like " & txtSearch.Text & " order by Persal No"
datPrimaryRS.Recordset.Open
If datPrimaryRS.MaxRecords = 0 Then
datPrimaryRS.Recordset.Close
datPrimaryRS.RecordSource = "Select * from [HRM] order by Persal No"
datPrimaryRS.Recordset.Open
If MsgBox("No Records were Found. Find Again...", vbYesNo + vbExclamation, "No Records..."
= vbYes Then
chkSearch.Value = Checked
txtSearch.SetFocus
Else
chkSearch.Value = Unchecked
txtSearch.Text = "<<Type Name Here>>"
End If
Else: MsgBox "Records Found...", vbInformation, "Found..."
chkSearch.Value = Unchecked
txtSearch.Text = "<<Type Name Here>>"
End If
End Sub
Thanks
tjbvo (Nexes)
Everything is working fine, but I need to add a Search Button, to search for existing records, and then to display (move to ) the relevant record using the same database.
Attached please find the code I am using, but it has faults ??
Private Sub cmdSearch_Click()
'The % means all Records that starts with example an A must be Find.
datPrimaryRS.Recordset.Close
datPrimaryRS.Recordset.Source = "Select * from [HRM] where Persal No like " & txtSearch.Text & " order by Persal No"
datPrimaryRS.Recordset.Open
If datPrimaryRS.MaxRecords = 0 Then
datPrimaryRS.Recordset.Close
datPrimaryRS.RecordSource = "Select * from [HRM] order by Persal No"
datPrimaryRS.Recordset.Open
If MsgBox("No Records were Found. Find Again...", vbYesNo + vbExclamation, "No Records..."
chkSearch.Value = Checked
txtSearch.SetFocus
Else
chkSearch.Value = Unchecked
txtSearch.Text = "<<Type Name Here>>"
End If
Else: MsgBox "Records Found...", vbInformation, "Found..."
chkSearch.Value = Unchecked
txtSearch.Text = "<<Type Name Here>>"
End If
End Sub
Thanks
tjbvo (Nexes)