Well the queries are a bit complicated, and I'm not sure whether you'll be into going through them, are you sure quieies are the problem?
Table: Distribution
Id_Distribution, Autonumber {Index}
Id_Volunteer, Number (Child Related to Volunteers)
Id_Customer, Number (Child Related to Customers)
Id,Delivery, Number (Child Related to Delivery)
Amount, Number
Remarks, Memo
Table: Customers
Id_Customer, Autonumber {Index}
Id_City, Number (Child Related to City)
Lname, Text
Fname, Text
Table: City
Id_City, Autonumber {Index}
CityName, Text
Table: Volunteers
Id_Volunteer, Autonumber {Index}
Full_Name, Text
Table: Delivery
Id_Delivery, Autonumber {Index}
Date_Delivery, Date/Time
Id_Type_Delivery, Number (Child Related to Type_Delivery)
Table: Type_Delivery
Id_Type_Delivery, Autonumber {Index}
TypeDeliveryName, Text
forDistributionEdit:
Code:
SELECT Distribution.Id_Distribution, Distribution.Id_Delivery, Distribution.Amount, IIf(IsNull([amount]),1,[amount]) AS Amount1, Distribution.Id_Customer, [TypeDeliveryName] & ' - ' & [Date_Delivery] AS Expr2, City.Id_City, City.CityName, Distribution.Id_Volunteer, [Lname] & ' ' & [Fname] AS Expr1, Distribution.Remarks, Type_Delivery.Id_Type_Delivery
FROM Type_Delivery INNER JOIN (Delivery INNER JOIN ((City INNER JOIN Customers ON City.Id_City = Customers.Id_City) INNER JOIN Distribution ON Customers.Id_Customer = Distribution.Id_Customer) ON Delivery.Id_Delivery = Distribution.Id_Delivery) ON Type_Delivery.Id_Type_Delivery = Delivery.Id_Type_Delivery
ORDER BY Distribution.Id_Distribution;
forDistributionEditExpanded:
Code:
SELECT T.Id_Distribution, T.Id_Delivery, T.Amount1, [TypeDeliveryName] & ' - ' & [Date_Delivery] AS Expr2, T.Id_City, T.CityName, T.Id_Customer, T.Id_Volunteer, T.Remarks, Type_Delivery.Id_Type_Delivery
FROM tblCount AS C, Type_Delivery INNER JOIN ((forDistributionEdit AS T INNER JOIN Customers ON T.Id_Customer = Customers.Id_Customer) INNER JOIN Delivery ON T.Id_Delivery = Delivery.Id_Delivery) ON Type_Delivery.Id_Type_Delivery = Delivery.Id_Type_Delivery
WHERE (((C.Count)<=[T].[Amount1]));
Here's the VBA code that changes RecordSources:
Code:
Private Sub cmdView_Click()
Me.FilterOn = False
Select Case Me.Form.RecordSource
Case "forDistributionEdit"
Me.Form.RecordSource = "forDistributionEditExpanded"
GoTo 1
Case "forDistributionEditExpanded"
Me.Form.RecordSource = "forDistributionEdit"
End Select
1
DoEvents
Call subApplyFilter
End Sub
Code:
Private Sub subApplyFilter()
Dim frm As Form
Dim ctl As Control
Dim strFilter As String
Set frm = Forms!DistributionEdit
'checking all controls
For Each ctl In frm.Controls
'goes through filter combos
If Left(ctl.Name, 4) = "cbo1" Then
If Not IsNull(ctl.Value) Then
strFilter = strFilter & " And " & frm.RecordSource & "." & _
Right(ctl.Name, Len(ctl.Name) - 4) & " = " & ctl.Value
End If
'goes through filter toggle
ElseIf ctl.Name = "tgl1Remarks" Then
If ctl.Value = True Then _
strFilter = strFilter & " And " & frm.RecordSource & "." & "Remarks Is Not Null"
End If
Next ctl
'if exists, cleans first "And"
If InStr(strFilter, " And") = 1 Then _
strFilter = Right(strFilter, Len(strFilter) - 5)
'assigns filter
Me.Filter = strFilter
Me.FilterOn = True
End Sub
Hope I won't be banned for this, heh