Advertisement

05.14.2008 at 12:46PM PDT, ID: 23402883
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.9

Using VBA to filter data

Asked by bluefeet10 in Microsoft Access Database, Access Coding/Macros

Tags: ,

Hi Everyone-
I am fairly new to developing with VBA and I am stuck on a problem. I have an Access database that current runs a screen scraping process to get data. The screens are being retired, so I need to connect to another source. The data from the new source is generated in XML.

Someone has previously written the code to get the data and I can retrieve most of the data that I need but the current screen scraping method uses a very long WHERE clause in the Access query. I am trying to figure out how to filter multiple items in the new query in VBA.

The current VBA routine only allows me to Filter on one item at a time, if I add multiple items they overwrite the previous filter.

Is there anyway to combine the multiple filters using an 'AND'? Like I said I am relatively new to this stuff and I don't know what to do to fix this.

Any help would be appreciated.

ThanksStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
Filter Routine:
Public Function Filter(ByVal int_Field As ReturnedTransactions, ByVal int_Filter As gt_Filter, ByVal str_OnCriteria As String) As Boolean
    
       Dim str_Filter As String        
   
       Select Case int_Filter
           Case 0: str_Filter = " =  '" & str_OnCriteria & "'"
           Case 1: str_Filter = " <  '" & str_OnCriteria & "'"
           Case 2: str_Filter = " <= '" & str_OnCriteria & "'"
           Case 3: str_Filter = " >  '" & str_OnCriteria & "'"
           Case 4: str_Filter = " >= '" & str_OnCriteria & "'"
           Case 5: str_Filter = " <> '" & str_OnCriteria & "'"
           Case 6: str_Filter = " LIKE '*" & str_OnCriteria & "*'"
           Case Else: Exit Function
       End Select
   
       RSet_Returned.Filter = str_ReturnField(int_Field) & str_Filter
   
       Select Case RSet_Returned.RecordCount
           Case Is > 0: Filter = True
           Case Else:   Filter = False
       End Select
End Function
 
Query:
Public Sub GetTransactions()
    Dim int_SheetRow    As Integer:     int_SheetRow = 2
 
    With wks_testData.Cells
        .ClearContents
        .ClearFormats
    End With
 
    With cls_GetTrans
        .NewSearch
        .SetValue gt_AccountID, "00000000"              
        .SetValue gt_ByDate, "True"                    '
        .SetValue gt_FromDate, "05/09/08"
        .SetValue gt_ToDate, "05/12/08"            
        .SetValue gt_RetrieveAllTransactions, "True"            
                
        If Not .ExecuteSearch Then MsgBox "No records were found", vbOKOnly, "No Records ": Exit Sub
            'this is where I need to be able to filter on multiple items. The second one overwrites the first. 
            'Is there a way to use an AND to combine multiple filter statements
            .Filter gt_DCCode, gt_IsEqual, "True"
            '.Filter gt_AType, gt_IsNotEqual, "XXXXX"
            
        .Save_ToFile "C:\Temp\Transactions.txt"             
        'Add the Headers to the sheet here
        Do Until .Returned_EOF
            wks_testData.Cells(int_SheetRow, "A") = .Returned(gt_ANumber)
            wks_testData.Cells(int_SheetRow, "B") = .Returned(gt_ExecDate)
            wks_testData.Cells(int_SheetRow, "C") = .Returned(gt_Qty)
            wks_testData.Cells(int_SheetRow, "D") = .Returned(gt_Description1)
            wks_testData.Cells(int_SheetRow, "E") = .Returned(gt_TAmount)
            wks_testData.Cells(int_SheetRow, "F") = .Returned(gt_Symbol)
            wks_testData.Cells(int_SheetRow, "G") = .Returned(gt_EffDate)
            wks_testData.Cells(int_SheetRow, "H") = .Returned(gt_TSourceCode)
            wks_testData.Cells(int_SheetRow, "I") = .Returned(gt_SNumber)
            wks_testData.Cells(int_SheetRow, "J") = .Returned(gt_Com)
            wks_testData.Cells(int_SheetRow, "K") = .Returned(gt_DrCrCode)
 
            int_SheetRow = int_SheetRow + 1
            .Returned_MoveNext
        Loop
    End With
    
    wks_testData.Cells.EntireColumn.AutoFit
End Sub
[+][-]05.15.2008 at 07:02AM PDT, ID: 21573707

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, Access Coding/Macros
Tags: VBA and XML, Filter or WHERE Clause
Sign Up Now!
Solution Provided By: jimhorn
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.20.2008 at 05:40AM PDT, ID: 21605562

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628