I've taken a search form from a database someone else designed, copied it to my database, and then changed fields etc. The form allows you to enter data against several fields and then returns matching records in a subform. Well, the original form returned matching records.
I have got it to where it will show ALL records in the subform. Not very useful BUT heading in the right direction.
The code sitting on my "search" button (minus repetitive bits for extra fields) is:
Private Sub Search_Click()
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If Topic
If Not IsNull(Me.Topic) Then
'Create Predicate
strWhere = strWhere & " AND " & "All Data.[Topic] = " & Me.Topic & ""
End If
' If Notes
If Nz(Me.Notes) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "All Data.Notes Like '*" & Me.Notes & "*'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Issues", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Browse_All_Issues.Form.Filter = strWhere
Me.Browse_All_Issues.Form.FilterOn = True
End If
End Sub
Topic is a combo box; all others are text boxes. The code apparently falls over on the 2nd last line " Me.Browse_All_Issues.Form.Filter = strWhere". The subform has a filter "1=1".
I really don't have a clue what I'm doing; my code 'writing' is limited to finding something that does what I want it to do, copying it, and changing field/table names etc. So, sentences comprised of single syllable words, and in "english" would be lovely ;-)
And just by the by: what does "Me." actually mean?
"Browse all issues" is the sub-form.
I have got it to where it will show ALL records in the subform. Not very useful BUT heading in the right direction.
The code sitting on my "search" button (minus repetitive bits for extra fields) is:
Private Sub Search_Click()
Dim strWhere As String
Dim strError As String
strWhere = "1=1"
' If Topic
If Not IsNull(Me.Topic) Then
'Create Predicate
strWhere = strWhere & " AND " & "All Data.[Topic] = " & Me.Topic & ""
End If
' If Notes
If Nz(Me.Notes) <> "" Then
' Add it to the predicate - match on leading characters
strWhere = strWhere & " AND " & "All Data.Notes Like '*" & Me.Notes & "*'"
End If
If strError <> "" Then
MsgBox strError
Else
'DoCmd.OpenForm "Browse Issues", acFormDS, , strWhere, acFormEdit, acWindowNormal
If Not Me.FormFooter.Visible Then
Me.FormFooter.Visible = True
DoCmd.MoveSize Height:=Me.WindowHeight + Me.FormFooter.Height
End If
Me.Browse_All_Issues.Form.Filter = strWhere
Me.Browse_All_Issues.Form.FilterOn = True
End If
End Sub
Topic is a combo box; all others are text boxes. The code apparently falls over on the 2nd last line " Me.Browse_All_Issues.Form.Filter = strWhere". The subform has a filter "1=1".
I really don't have a clue what I'm doing; my code 'writing' is limited to finding something that does what I want it to do, copying it, and changing field/table names etc. So, sentences comprised of single syllable words, and in "english" would be lovely ;-)
And just by the by: what does "Me." actually mean?
"Browse all issues" is the sub-form.
Last edited: