Private Sub cmdSearch_Click()
Dim SQL As String
Screen.MousePointer = vbHourglass
' generate SQL search query
SQL = "Select * from Employee "
SQL = SQL & "where lname like '" & _
Replace(txtSearchName.Text, "'", "''") & "%' "
SQL = SQL & "Order by lName,fname"
' execute the query
deMain.rsEmployee.Close
deMain.rsEmployee.Open SQL, deMain.conPubs
' Rebind bound controls to new de recordset
Call Rebind
If deMain.rsEmployee.RecordCount = 0 Then
MsgBox "No employee matching your criteria " & _
"were found."
End If
Screen.MousePointer = vbDefault
End Sub
Private Sub Rebind()
Dim Ctl As Control
' rebind data grid to new recordset
Set dbgridEmployee.DataSource = deMain
' rebind each bound control to new recordset
For Each Ctl In Me.Controls
If TypeOf Ctl Is CheckBox Or _
TypeOf Ctl Is TextBox Or _
TypeOf Ctl Is DataCombo Then
If Ctl.DataField <> " Then Set _
Ctl.DataSource = deMain
End If
Next
' hide details and disable delete if no records
If deMain.rsEmployee.RecordCount > 0 Then
FrameEmployee.Visible = True
cmdDelete.Enabled = True
Else
FrameEmployee.Visible = False
cmdDelete.Enabled = False
End If
End Sub
|