Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-21-2007, 09:34 AM
WLH WLH is offline
Registered User
 
Join Date: Aug 2007
Posts: 10
WLH is on a distinguished road
Clearing multiple form fields kills search function

I've got a form with 3 search fields. The fields are not intended to be used in conjunction, but they do all display their results in the same results pane.

When I first start the application, MY search functionality works just as it's supposed to. But when I clear the fields either with the "Clear Filter" button I've got in place or if I delete the information from ANY of the three fields Search functionality stops.

here is the code I have attached to the fields and corresponding buttons


Private Sub Command18_Click()
Me.DocFilter.SetFocus
Me.DocFilter.Text = ""
Me.DocFilter2.SetFocus
Me.DocFilter2.Text = ""
Me.DocFilter3.SetFocus
Me.DocFilter3.Text = ""
Me.FilterOn = False
List0.Requery
End Sub

Private Sub Command4_Click()
Me.FilterOn = False
List0.Requery
End Sub

Private Sub DocFilter_AfterUpdate()
Command4_Click
End Sub

Private Sub DocFilter2_AfterUpdate()
Command4_Click
End Sub

Private Sub DocFilter3_AfterUpdate()
Command4_Click
End Sub


Private Sub List0_Click()
If Len(Me.List0.Value) > 0 Then
Me.Filter = "ID_NO=" & Me.List0.Value
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End Sub

Any thoughts?
Reply With Quote
Sponsored Links
  #2  
Old 08-21-2007, 09:43 AM
lagbolt's Avatar
lagbolt lagbolt is online now
AWF VIP
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 1,922
lagbolt is a jewel in the roughlagbolt is a jewel in the roughlagbolt is a jewel in the rough
What's the RowSource of the list? I don't see any connection between the List and TextBoxes. Everything removes the filter except a click on the list.
What does requerying the list do?
__________________
Vista Ultimate | Access 2007 | VB.NET 2.0 | Biesse CNC | AutoCAD 2007
Reply With Quote
  #3  
Old 08-21-2007, 09:48 AM
WLH WLH is offline
Registered User
 
Join Date: Aug 2007
Posts: 10
WLH is on a distinguished road
I've go a SQL query attached to List0. The search criteria entered into the DocFilter fields is inserted into that query to populate List0.

Is that what you needed to know? I'm far from an expert, or even intermediate for that matter. I'm just trying to learn.
Reply With Quote
  #4  
Old 08-21-2007, 10:35 AM
lagbolt's Avatar
lagbolt lagbolt is online now
AWF VIP
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 1,922
lagbolt is a jewel in the roughlagbolt is a jewel in the roughlagbolt is a jewel in the rough
What do you mean the "Search functionality stops." Do you get errors? List won't populate?
Also, post the query text. That seems an integral part of the system you want to troubleshoot.
__________________
Vista Ultimate | Access 2007 | VB.NET 2.0 | Biesse CNC | AutoCAD 2007
Reply With Quote
  #5  
Old 08-21-2007, 10:38 AM
WLH WLH is offline
Registered User
 
Join Date: Aug 2007
Posts: 10
WLH is on a distinguished road
After I clear the DocFilter fields the list will not longer populate regardless of the information entered.

here is the query in use


SELECT Drawing.DWG_NO, Drawing.DRAWING_desc, Drawing.ID_NO
FROM Drawing
WHERE (((Drawing.DWG_NO)
Like Replace("*" & Replace(Replace(Replace(Replace([Form].[DocFilter],"/","*"),"-","*"),"\","*"),"_","*") & "*","**","*")))
OR (((Drawing.DRAWING_desc) Like "*" & [Form].[DocFilter2] & "*"))
OR (((Drawing.EQUIP_NO) Like Replace("*" & Replace(Replace(Replace(Replace([Form].[DocFilter3],"/","*"),"-","*"),"\","*"),"_","*") & "*","**","*")));
Reply With Quote
  #6  
Old 08-21-2007, 11:03 AM
lagbolt's Avatar
lagbolt lagbolt is online now
AWF VIP
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 1,922
lagbolt is a jewel in the roughlagbolt is a jewel in the roughlagbolt is a jewel in the rough
Even if you enter something in all three of your search boxes?
__________________
Vista Ultimate | Access 2007 | VB.NET 2.0 | Biesse CNC | AutoCAD 2007
Reply With Quote
  #7  
Old 08-21-2007, 11:11 AM
WLH WLH is offline
Registered User
 
Join Date: Aug 2007
Posts: 10
WLH is on a distinguished road
Ah

If I enter something that would return results in all three boxes, then I get results. Even after Clearing the filter.

If I enter something in box 1 and 3(numeric), I get results

If I enter something in box 1 and 2, or box 2 and 3, I get nothing.

If there something wrong with my query, Or in the VB code causing the error? Or, knowing my luck, both?
Reply With Quote
  #8  
Old 08-21-2007, 11:17 AM
WLH WLH is offline
Registered User
 
Join Date: Aug 2007
Posts: 10
WLH is on a distinguished road
bit more clarification, sorry.

When I initially open the Form I can enter information into any combination of the 3 fields I'm using and get results.

If I modify the information in any of the fields I get updated results to match the input.

The moment I hit the "Clear Filter" button (command18) I have to use either fields 1,3 or 1,2,3 to get results.

I get no results from single field criteria, or fields 1,2 or 2,3

The same thing happens if i highlight and delete information from any 1 of the fields (this includes deleting, or backspacing the field data away)

so....is it something simple, or am I in a tight spot?
Reply With Quote
  #9  
Old 08-21-2007, 07:32 PM
lagbolt's Avatar
lagbolt lagbolt is online now
AWF VIP
 
Join Date: Mar 2004
Location: Vancouver BC
Posts: 1,922
lagbolt is a jewel in the roughlagbolt is a jewel in the roughlagbolt is a jewel in the rough
I believe the problem is with the WHERE clause of your query. If you delete data from a text box the value is Null. All math or comparisons done with a Null results in a Null. I believe this is killing your query.

The only criteria that should appear in the query'e WHERE clause are those for which a textbox on the form has usable data. This complicates your life since you'll need to construct the where clause dynamically.

What I would do is remove the complicated nested Replace() statements from the query. Troubleshooting or debugging something that looks like this
Code:
Replace("*" & Replace(Replace(Replace(Replace([Form].[DocFilter3],"/","*"),"-","*"),"\","*"),"_","*") & "*","**","*")))
is...well...tedious. Are you replacing all those special characters with '*'?

Create a function that does this. Run your user input through that function. Save the function's output to a hidden textbox or variable. If your function's return value has data suitable for a search, ie 'Not IsNull()', then write the where clause and assign the resulting sql to the rowsource of the list.

Does that make sense? Does that sound really hard? Heres a little chunk of code that replaces various characters in a string with some other character.

Code:
Function ReplaceChars(ByVal someString As String) As String
   Const REPLACE_WITH As String = "*"
   Dim varChars As Variant
   Dim var As Variant
   
   'construct array of characters to be replaced
   varChars = Split("\ / _ -")
   'traverse the array
   For Each var In varChars
      'replace the current var with the REPLACE_WITH
      someString = Replace(someString, CStr(var), REPLACE_WITH)
   Next var
   'assign to function
   ReplaceChars = someString
End Function
This exposes a where clause that recalculates everytime you reference it...
Code:
Property Get WhereClause() As String
   Dim str As String
   If Not IsNull(Me.DocFilter) Then
      str = "OR Drawing.DWG_NO Like '*" & Me.ReplaceChars(Me.DocFilter) & "*' "
   End If
   If Not IsNull(Me.DocFilter2) Then
      str = str & "OR Drawing.DRAWING_desc Like '*" & Me.DocFilter2 & "*' "
   End If
   If Not IsNull(Me.DocFilter3) Then
    str = str & "OR Drawing.EQUIP_NO Like '*" & Me.ReplaceChars(Me.DocFilter3) & "*' "
   End If
   If Len(str) > 0 Then str = "WHERE False " & str
   WhereClause = str
End Property
So you're almost there. Now, on every AfterUpdate you want to set the rowsource of the list to ...
Code:
me.lst.rowsource = _
  "SELECT Drawing.DWG_NO, Drawing.DRAWING_desc, Drawing.ID_NO " & _
  "FROM Drawing " & _
  WhereClause
Maybe you need to requery the list when you change the rowsource. Not sure.

See if that gets you somewhere.
__________________
Vista Ultimate | Access 2007 | VB.NET 2.0 | Biesse CNC | AutoCAD 2007
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling Multiple Fields on a form Daveyk01 Modules & VBA 11 07-15-2007 04:40 AM
Criteria Multiple Search Fields IN Query natural Queries 0 03-29-2007 03:45 AM
SQL to search multiple fields Miethr Queries 13 07-28-2006 04:41 AM
Another Noob question: Creating search form tangouniform General 3 04-26-2006 01:05 PM
custom search form datacontrol Modules & VBA 4 09-21-2003 11:21 AM


All times are GMT -8. The time now is 09:56 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World