Domanda

Hello Everyone I am at a dilemma I am trying to find out a way to filter out certain data in a column field I have an idea on how to do this but I do not know the correct syntax to use. First here is the table and here is the code structure I would like to write.

for i=1 to length of column First Match
    for j=1 to length of column Second Match

    If ((value of the data in column First Match = 15) OR (value of the data in column FirstMatch = 1)) AND
       ((value of the data in column Second Match = 15) OR (value of the data in column Second Match = 1)) 
    Then
        Filter the data and append so the filtered datas are saved for both First Match and Second Match
    end if
    next
next

I am trying to filter out the data that is a 15 and 1 so that only data that have the values 0,2,3,4,5,6...14 will be shown for instance the information of john and steve will not be shown because both the first and second match fields have a 1 or 15 but the rest of data will be shown my form is a split form setup.

Is my method correct?


First Name    Last Name    First Match    Second Match
James         Matheson         0               2
Monroe        Labonson         4               3
Barack        Obama            2               5
Frederick     Douglas          3               4
Steve         MCGowan          1               1
John          Seals            15              15
Mike          Omalley          14              15



Set rs = CurrentDb.OpenRecordset("Table1")

Do While Not rs.EOF
If rs!Fields("First Match") > 1 And rs!Fields("First Match") < 15 And rs!Fields("Second Match") > 1 And rs!Fields("Second Match") < 15 Then

End If
Loop
È stato utile?

Soluzione 2

I have found the solution apparently it was just a misunderstanding because the first time I tried this code I thought it was wrong but it was because my field names did not have spaces in between the first time I wrote them.

Me.Filter = ""
Me.Filter = "[First Nam]<>'Jamie' AND [Last Nam]<>'Cartman'"
Me.FilterOn = True 

Altri suggerimenti

With a better understanding (I hope) I've reproduced your data in Access and built a query that does what you seem to ask. The best way to see this is to create a new query, not add a table, and go directly to SQL view. Paste the following SQL statement (the one in quotes) in and replace matchFilter with your table name.

In your event code you can create a recordset based on the SQL:

Dim sSQL as string, rs as Recordset

sSQL = "SELECT matchFilter.[First Name], matchFilter.[Last Name], matchFilter.[First Match], matchFilter.[Second Match] " & _
"FROM matchFilter " & _
"WHERE ((([First Match]<>1 And [First Match]<>15 And [Second Match]<>1 And [Second Match]<>15)=True))"
 Set rs = CurrentDB.OpenRecordset(sSQL)
 ' now do what you want

Wrong answer below!

Dim rs as Recordset
Set rs = CurrentDB.OpenRecordset("yourTableName")
Do While Not rs.EOF
    If rs!Fields("col1") > 1 AND rs!Fields("col1") < 15 AND rs!Fields("col2") > 1 AND rs!Fields("col2") Then
        'do what you have to do with filtered out records
    End If
Loop
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top