J
JK
I have a main form and a subform. On the main form I have a text box called
txtSearch. I want to be able to using this text box to search for a record in
the subform. As you type in txtSearch the subform should change to only
display records that match whats been typed in txtSearch.
Can anyone find the problem with the following code?
I'm getting an error on sfrmForm
Private Sub TypeDown(strSearch As String)
On Error Resume Next
Dim strSQL As String
If strSearch = "" Then
strSQL = "qryClassItems_Main"
Else
'modify this to desired query
strSQL = "SELECT * FROM qryClassItems_Main" & _
" WHERE [ClassofTrade] Like '*" & strSearch & "*' " & _
" OR [ClassDesc] Like '*" & strSearch & "*' " ' last line
ends like this
End If
Me.sfrmForm.Form.RecordSource = strSQL
Me.sfrmForm.Form.Requery
Me.txtSearch.SetFocus
Me.txtSearch.SelStart = Len(Me.txtSearch)
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim strSearch As String
Dim strSQL As String
strSQL = "qryClassItems_Main" 'change this todesired query
Me.sfrmForm.Form.RecordSource = strSQL
Me.sfrmForm.Form.Requery
Me.txtSearch.SetFocus
End Sub
Private Sub txtSearch_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Requery
TypeDown IIf(IsNull(Me.txtSearch), "", Me.txtSearch)
End Sub
txtSearch. I want to be able to using this text box to search for a record in
the subform. As you type in txtSearch the subform should change to only
display records that match whats been typed in txtSearch.
Can anyone find the problem with the following code?
I'm getting an error on sfrmForm
Private Sub TypeDown(strSearch As String)
On Error Resume Next
Dim strSQL As String
If strSearch = "" Then
strSQL = "qryClassItems_Main"
Else
'modify this to desired query
strSQL = "SELECT * FROM qryClassItems_Main" & _
" WHERE [ClassofTrade] Like '*" & strSearch & "*' " & _
" OR [ClassDesc] Like '*" & strSearch & "*' " ' last line
ends like this
End If
Me.sfrmForm.Form.RecordSource = strSQL
Me.sfrmForm.Form.Requery
Me.txtSearch.SetFocus
Me.txtSearch.SelStart = Len(Me.txtSearch)
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim strSearch As String
Dim strSQL As String
strSQL = "qryClassItems_Main" 'change this todesired query
Me.sfrmForm.Form.RecordSource = strSQL
Me.sfrmForm.Form.Requery
Me.txtSearch.SetFocus
End Sub
Private Sub txtSearch_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Requery
TypeDown IIf(IsNull(Me.txtSearch), "", Me.txtSearch)
End Sub