Search Form Code

SueBK

Registered User.
Local time
Today, 11:45
Joined
Apr 2, 2009
Messages
197
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.
 
Last edited:
I found a different way of doing it. The search boxes are in the form header, the results are returned in the details as a continous form. Couldn't make the combobox code work, so I just removed it from the search options.

Fiddling with formatting now. Can't get my results to 'grow', so the output is being truncated, which is annoying.

BUT, I do now have a new question. At the moment my search is returning several entries for each record. I'm assuming this is because of the way I set up the tables. It's a database of scientific references, many of which have more than one author. I'm guessing that each return in my search is because of the individual authors.

Is there a code that I can put that will say "return only the first entry for each BookID" IF "Author" is blank? (If there's a search on the Author obviously I want to return all entries for that name.)
 
Last edited:

Users who are viewing this thread

Back
Top Bottom