N
Naz
Hi
I've been given a database to manage and update....but one of the forms i
have moved to the new database, a rudimentary search form doesn't seem to
work properly. Its a simple form with first name surname and address unbound
text fields etc...that the user populates and clicks a Find button....a new
form opens up with the results......but for some reason it works fine on the
old database but on the new one it won't work unless i hit return or move to
another field after putting in a name or address. If i just type a name and
click the find button it simply brings up nothing.....i've tried to debug the
code and found that even if something is put in a field it doesn't seem to
register on the FieldName <>"" part of the code
The only change i made to the code was to change some field names...
Private Sub FINDRECORDS_Click()
On Error GoTo Err_FINDRECORDS_Click
filt = doFilter()
DoCmd.OpenForm "frm_ReturnSearchResults", , , filt
Exit_FINDRECORDS_Click:
Exit Sub
Err_FINDRECORDS_Click:
MsgBox Err.Description
Resume Exit_FINDRECORDS_Click
End Sub
-------------------------------------------------------------------------
Private Function doFilter() As String
Dim filt_string As String
Dim WildCardIt As String
Dim TestPot As String
If Wildcard = 0 Then
WildCardIt = "*"
Else
WildCardIt = ""
End If
If Me.FAMILY_NAME <> "" Then
MsgBox "something here"
Me.FAMILY_NAME = WildCardIt & Me.FAMILY_NAME & WildCardIt
filt_string = filt_string + "[FAMILY_NAME] Like
[Forms]![frm_Search_Page]![FAMILY_NAME]"
End If
If Me.FIRST_NAME <> "" Then
Me.FIRST_NAME = WildCardIt & Me.FIRST_NAME & WildCardIt
do_and filt_string
filt_string = filt_string + "[FIRST_NAME] Like
[Forms]![frm_Search_Page]![FIRST_NAME]"
End If
If Me.SURNAME <> "" Then
Me.SURNAME = WildCardIt & Me.SURNAME & WildCardIt
do_and filt_string
filt_string = filt_string + "[SURNAME] Like
[Forms]![frm_Search_Page]![SURNAME]"
End If
If Me.PERSREF <> "" Then
Me.PERSREF = Me.PERSREF & WildCardIt
do_and filt_string
filt_string = filt_string + "[PERSREF] Like
[Forms]![frm_Search_Page]![PERSREF] "
End If
If Me.OPEN_DATE <> "" Then
Me.OPEN_DATE = WildCardIt & Me.OPEN_DATE & WildCardIt
do_and filt_string
filt_string = filt_string + "[OPEN_DATE] Like
[Forms]![frm_Search_Page]![OPEN_DATE] "
End If
If Me.CLOSE_DATE <> "" Then
Me.CLOSE_DATE = WildCardIt & Me.CLOSE_DATE & WildCardIt
do_and filt_string
filt_string = filt_string + "[CLOSE_DATE] Like
[Forms]![frm_Search_Page]![CLOSE_DATE] "
End If
If Me.ADDRESS <> "" Then
Me.ADDRESS = WildCardIt & Me.ADDRESS & WildCardIt
do_and filt_string
filt_string = filt_string + "[ADDRESS] Like
[Forms]![frm_Search_Page]![ADDRESS] "
End If
If Me.ACCESSION_NUMBER <> "" Then
Me.ACCESSION_NUMBER = WildCardIt & Me.ACCESSION_NUMBER & WildCardIt
do_and filt_string
filt_string = filt_string + "[ACCESSION_NUMBER] Like
[Forms]![frm_Search_Page]![ACCESSION_NUMBER] "
End If
If Me.RMS_FILE_REF <> "" Then
Me.RMS_FILE_REF = WildCardIt & Me.RMS_FILE_REF & WildCardIt
do_and filt_string
filt_string = filt_string + "[RMS_FILE_REF] Like
[Forms]![frm_Search_Page]![RMS_FILE_REF] "
End If
doFilter = filt_string
End Function
________________________________________________________
Private Sub do_and(ByRef str As String)
If str <> "" Then
str = str + " And "
End If
End Sub
All help is greatly appreciated
I've been given a database to manage and update....but one of the forms i
have moved to the new database, a rudimentary search form doesn't seem to
work properly. Its a simple form with first name surname and address unbound
text fields etc...that the user populates and clicks a Find button....a new
form opens up with the results......but for some reason it works fine on the
old database but on the new one it won't work unless i hit return or move to
another field after putting in a name or address. If i just type a name and
click the find button it simply brings up nothing.....i've tried to debug the
code and found that even if something is put in a field it doesn't seem to
register on the FieldName <>"" part of the code
The only change i made to the code was to change some field names...
Private Sub FINDRECORDS_Click()
On Error GoTo Err_FINDRECORDS_Click
filt = doFilter()
DoCmd.OpenForm "frm_ReturnSearchResults", , , filt
Exit_FINDRECORDS_Click:
Exit Sub
Err_FINDRECORDS_Click:
MsgBox Err.Description
Resume Exit_FINDRECORDS_Click
End Sub
-------------------------------------------------------------------------
Private Function doFilter() As String
Dim filt_string As String
Dim WildCardIt As String
Dim TestPot As String
If Wildcard = 0 Then
WildCardIt = "*"
Else
WildCardIt = ""
End If
If Me.FAMILY_NAME <> "" Then
MsgBox "something here"
Me.FAMILY_NAME = WildCardIt & Me.FAMILY_NAME & WildCardIt
filt_string = filt_string + "[FAMILY_NAME] Like
[Forms]![frm_Search_Page]![FAMILY_NAME]"
End If
If Me.FIRST_NAME <> "" Then
Me.FIRST_NAME = WildCardIt & Me.FIRST_NAME & WildCardIt
do_and filt_string
filt_string = filt_string + "[FIRST_NAME] Like
[Forms]![frm_Search_Page]![FIRST_NAME]"
End If
If Me.SURNAME <> "" Then
Me.SURNAME = WildCardIt & Me.SURNAME & WildCardIt
do_and filt_string
filt_string = filt_string + "[SURNAME] Like
[Forms]![frm_Search_Page]![SURNAME]"
End If
If Me.PERSREF <> "" Then
Me.PERSREF = Me.PERSREF & WildCardIt
do_and filt_string
filt_string = filt_string + "[PERSREF] Like
[Forms]![frm_Search_Page]![PERSREF] "
End If
If Me.OPEN_DATE <> "" Then
Me.OPEN_DATE = WildCardIt & Me.OPEN_DATE & WildCardIt
do_and filt_string
filt_string = filt_string + "[OPEN_DATE] Like
[Forms]![frm_Search_Page]![OPEN_DATE] "
End If
If Me.CLOSE_DATE <> "" Then
Me.CLOSE_DATE = WildCardIt & Me.CLOSE_DATE & WildCardIt
do_and filt_string
filt_string = filt_string + "[CLOSE_DATE] Like
[Forms]![frm_Search_Page]![CLOSE_DATE] "
End If
If Me.ADDRESS <> "" Then
Me.ADDRESS = WildCardIt & Me.ADDRESS & WildCardIt
do_and filt_string
filt_string = filt_string + "[ADDRESS] Like
[Forms]![frm_Search_Page]![ADDRESS] "
End If
If Me.ACCESSION_NUMBER <> "" Then
Me.ACCESSION_NUMBER = WildCardIt & Me.ACCESSION_NUMBER & WildCardIt
do_and filt_string
filt_string = filt_string + "[ACCESSION_NUMBER] Like
[Forms]![frm_Search_Page]![ACCESSION_NUMBER] "
End If
If Me.RMS_FILE_REF <> "" Then
Me.RMS_FILE_REF = WildCardIt & Me.RMS_FILE_REF & WildCardIt
do_and filt_string
filt_string = filt_string + "[RMS_FILE_REF] Like
[Forms]![frm_Search_Page]![RMS_FILE_REF] "
End If
doFilter = filt_string
End Function
________________________________________________________
Private Sub do_and(ByRef str As String)
If str <> "" Then
str = str + " And "
End If
End Sub
All help is greatly appreciated