O
omar.norton
I have created a database with a search form called frmStockSearch
based on Allen Browne's (http://www.allenbrowne.com/ser-62.html)
excellent example, which works absolutely fine. In fact, it worked so
well that I copied the search form into another database, renamed it,
adapted the code and expanded it to make another search form called
frmCustomerSearch. This worked absolutely fine for a long time until
recently when my boss asked me to add another piece of search criteria
to the form. The form still works fine until I enter something into
this new search box when I get runtime error 2450 saying that
frmstocksearch (the old form!!) cannot be found!! I have been through
all the code for the entire project with a fine toothcomb and there is
not one reference to the old search form name. I have checked every
aspect of access I can think of and I cannot find any problems. The
search form still works fine with any other search criteria. Here is
the code for the serch box that brings up the error:
Private Sub cmdFilter_Click()
'Purpose Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Note We tack " AND " on the end of each condition so you
can easily add more
' search boxes; we remove the trailing " AND " at the
end.
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
'***********************************************************************
'Look at each search box, and build up the criteria string from
the non-blank ones.
'***********************************************************************
If Not IsNull(Me.cboRegion) Then
strWhere = strWhere & "([Region] = """ & Me.cboRegion & """)
AND "
End If
'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's
Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ")
to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'String is empty
Me.FilterOn = False
Else 'String is not empty
strWhere = Left$(strWhere, lngLen)
'Finally, apply the string as the form's Filter, and store it
in an invisible text box
'for future use
Debug.Print strWhere
Me.Filter = strWhere
txtstrWhere = strWhere
Me.FilterOn = True
End If
Me.txtID.SetFocus
End Sub
Note there are lots of other search criteria that I have not bothered
to put in as these work fine.
Thank you in advance for any help!!!
based on Allen Browne's (http://www.allenbrowne.com/ser-62.html)
excellent example, which works absolutely fine. In fact, it worked so
well that I copied the search form into another database, renamed it,
adapted the code and expanded it to make another search form called
frmCustomerSearch. This worked absolutely fine for a long time until
recently when my boss asked me to add another piece of search criteria
to the form. The form still works fine until I enter something into
this new search box when I get runtime error 2450 saying that
frmstocksearch (the old form!!) cannot be found!! I have been through
all the code for the entire project with a fine toothcomb and there is
not one reference to the old search form name. I have checked every
aspect of access I can think of and I cannot find any problems. The
search form still works fine with any other search criteria. Here is
the code for the serch box that brings up the error:
Private Sub cmdFilter_Click()
'Purpose Build up the criteria string form the non-blank search
boxes, and apply to the form's Filter.
'Note We tack " AND " on the end of each condition so you
can easily add more
' search boxes; we remove the trailing " AND " at the
end.
Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria
string to append to.
'***********************************************************************
'Look at each search box, and build up the criteria string from
the non-blank ones.
'***********************************************************************
If Not IsNull(Me.cboRegion) Then
strWhere = strWhere & "([Region] = """ & Me.cboRegion & """)
AND "
End If
'***********************************************************************
'Chop off the trailing " AND ", and use the string as the form's
Filter.
'***********************************************************************
'See if the string has more than 5 characters (a trailng " AND ")
to remove.
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'String is empty
Me.FilterOn = False
Else 'String is not empty
strWhere = Left$(strWhere, lngLen)
'Finally, apply the string as the form's Filter, and store it
in an invisible text box
'for future use
Debug.Print strWhere
Me.Filter = strWhere
txtstrWhere = strWhere
Me.FilterOn = True
End If
Me.txtID.SetFocus
End Sub
Note there are lots of other search criteria that I have not bothered
to put in as these work fine.
Thank you in advance for any help!!!