PDA

View Full Version : ACCESS - filtered records only. Impossible?



grofszecheny
05-29-2015, 05:31 AM
Dear All,

I would like to ask for your help. The goal would be to create a function/macro/vba event or even update query in ACCESS, which modifies only those records, which were filtered by the user. As the filtering logic is always different, I could explain in other words: modify only the "visible" records.
The method would be pretty much simmilar when we make a filtering in excel, and copy the first cell until the last one (hidden cells are skipped).
It would be also possible to click the little triangle at the top-left corner ->paste it into excel ->import it in a new table ->create update query. But as the process would be a copy paste it may become a bit more complicated.
Is it possible to ask access to recognise the current existing filter (to apply it in a query)?
Do you have any other idea how is it possible to do this?

I have been searching google and forums for quite some time, haven't found any solution yet.
Creating a recordset does not work yet, because I dont know how to select only filtered records.

Many thanks in advance for your help!
Kind regards
Balint

jonh
05-29-2015, 07:43 AM
You wouldn't need to create a recordset for a form because it already has myform.recordset and myform.recordsetclone.

You can get the filter string from myform.filter and whether it it is active or not with myform.filteron


Private Sub Command0_Click()
'show the current filter ...
Debug.Print "Current filter = " & Me.Filter & vbNewLine

'... and if it is enabled or not
Debug.Print IIf(Me.FilterOn, "Filter is active", "Filter is not active") & vbNewLine

'ensure filter is off
Me.FilterOn = False

'set a new filter
Me.Filter = "[somefield]='somevalue'"

'print out unfiltered records
Debug.Print "--- unfiltered records ---"
printout

'turn filter on
Me.FilterOn = True

'print out filtered records
Debug.Print vbNewLine & "--- filtered records ---"
printout
End Sub

Private Sub printout()
With Me.RecordsetClone
Do Until .EOF
For Each f In .Fields
Debug.Print f.Value,
Next
Debug.Print
.MoveNext
Loop
End With
End Sub