Using Filters Or RecordSources

P

PC User

I have a continuous subform that has changing conditions of whether it
will be controled by a date range or not; also whether all its
checkboxes are selected or not. This amounts to a multitude of
possible combinations.

1. All checkboxes checked with no date range
2. All checkboxes checked with a date range
3. No checkboxes checked with no date range
4. No checkboxes checked with a date range.

The subform shows up like a list box with column headings and I also
have sort buttons on the column headings.

This requires the changing of conditions also.

1. Sort assending with no date range
2. Sort decending with no date range
3. Sort assending with a date range
4. Sort decending with a date range.

As you might guess the recordsource or filter can be constantly
changing with the users mouse click. I don't know which would be
easier (using filters or recordsources), because I can't get either to
work. Below are my two attempts. I use option toggle buttons to
indicate whether or not to filter (change recordsource) for the update
query.

Using filters
====================================
Private Sub btnSelectAll_Click()
Dim db As Database
Dim strSQL As String
Dim Frm As Form
Dim sfN As Form 'Program Notification SubForm
Set Frm = Forms!frmMainEntry.Form
Set sfN = Frm.[fctlNotifications].Form
strSQL = "qupdNotificationSelectionYes"
If NotificationFilter = 1 Then
sfN.Filter = ""
sfN.FilterOn = False
Else
sfN.Filter = "tblMainData.DueDate = #" & "Between
[Forms]![frmMainEntry]![BeginningDate] And
[Forms]![frmMainEntry]![EndingDate] & #"
sfN.FilterOn = True
End If
CurrentDb.Execute strSQL, dbFailOnError
sfN.Refresh
Form.Refresh
Me.txtCountSelected.SetFocus
Me.txtTotalRecords.SetFocus
End Sub
====================================
====================================


Using recordsources
====================================
Private Sub btnSelectAll_Click() 'Select all checkboxes meeting
criteria
Dim db As Database
Dim strSQL As String
Dim Frm As Form
Dim sfN As Form 'Program Notification SubForm
Set Frm = Forms!frmMainEntry.Form
Set sfN = Frm.[fctlNotifications].Form
If NotificationFilter = 1 Then
strSQL = "qupdNotificationSelectionYes "
CurrentDb.Execute strSQL, dbFailOnError
Else
Call CheckNotificationDates
strSQL = "qupdNotificationSelectionYesDates "
sfN.CurrentDb.Execute strSQL, dbFailOnError
End If
sfN.Refresh
Form.Refresh
Me.txtCountSelected.SetFocus
Me.txtTotalRecords.SetFocus
End Sub
====================================
I hope someone can help me with this. In the filter, I get an error
with the criteria. In the recordsource, I get an error in the
execution of the currentdb. This is a very busy subform.

Thanks,
pc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top