94Sport5sp
Registered User.
- Local time
- Today, 11:06
- Joined
- May 23, 2012
- Messages
- 115
Hi:
I have a form bound to a Crosstab Query. The form has a list box from which the user can select the items to be displayed. With code I then set the filter to this selected item. However, the form displays all records returned by the Query. I have used Debug.Print me.filter to verify that the filter is correct and now I am stuck.
Some background info:
The purpose of the form is to display summary information. The list box is tied to a different query which presents a list of areas to the user. The Crosstab Query does a summary of all areas. Because of the nature of the Crosstab Query my form does not have any fields bound to the Crosstab Query. Instead I have several unbound fields and then I use code to set the Control Source of each Unbound field to a field from the Crosstab Query. All of that works fine and my form displays the data properly. However, what I now want is to limit the display to the user selected area but my filter is having no effect.
Any thoughts.
My Crosstab Query:
TRANSFORM Sum(qryGLVendor.NetAmt) AS SumOfNetAmt
SELECT qryGLVendor.SaleDate, qryGLVendor.RegisterName
FROM qryGLVendor
GROUP BY qryGLVendor.SaleDate, qryGLVendor.RegisterName
PIVOT qryGLVendor.Item ;
My code to set the filter:
Me.Form.Filter = "RegisterName=" & """" & RegisterNameGlbl & """"
Debug.Print Me.Filter
My code to locate the open form and assign Control Source to the unbound fields:
Private Sub subFillCol()
Dim frm As Form, intI As Integer
Dim intJ As Integer
Dim vAmount As Variant
Dim intControls As Integer, intForms As Integer
Dim rst As DAO.Recordset
Dim fld As Field
Dim intCnt As Integer
Set rst = Me.Recordset
intForms = Forms.Count ' Number of open forms.
'Check if any forms are open
If intForms > 0 Then
' Loop thru all open forms looking for frmGLSum
For intI = 0 To intForms - 1
Set frm = Forms(intI)
Select Case frm.Name
'Populate form from query
Case "frmGLSum"
intCnt = 1
For Each fld In rst.Fields ' Print field names.
Select Case VarType(fld.Value)
Case 0 To 1 'Value is a Null or empty
'Debug.Print " Fld 01 "; intCnt; " Name "; fld.Name; " "; fld.Value
Me("Hdn" & intCnt) = fld.Name
Me("Col" & intCnt).ControlSource = fld.Name '""
More similar code to populate unbound fields.
End Select
intCnt = intCnt + 1
Next
intCnt = 1
End Select
Next intI
Else
MsgBox "No open forms.", vbExclamation, "Form Controls"
'End check for any forms open
End If
End Sub
I have a form bound to a Crosstab Query. The form has a list box from which the user can select the items to be displayed. With code I then set the filter to this selected item. However, the form displays all records returned by the Query. I have used Debug.Print me.filter to verify that the filter is correct and now I am stuck.
Some background info:
The purpose of the form is to display summary information. The list box is tied to a different query which presents a list of areas to the user. The Crosstab Query does a summary of all areas. Because of the nature of the Crosstab Query my form does not have any fields bound to the Crosstab Query. Instead I have several unbound fields and then I use code to set the Control Source of each Unbound field to a field from the Crosstab Query. All of that works fine and my form displays the data properly. However, what I now want is to limit the display to the user selected area but my filter is having no effect.
Any thoughts.
My Crosstab Query:
TRANSFORM Sum(qryGLVendor.NetAmt) AS SumOfNetAmt
SELECT qryGLVendor.SaleDate, qryGLVendor.RegisterName
FROM qryGLVendor
GROUP BY qryGLVendor.SaleDate, qryGLVendor.RegisterName
PIVOT qryGLVendor.Item ;
My code to set the filter:
Me.Form.Filter = "RegisterName=" & """" & RegisterNameGlbl & """"
Debug.Print Me.Filter
My code to locate the open form and assign Control Source to the unbound fields:
Private Sub subFillCol()
Dim frm As Form, intI As Integer
Dim intJ As Integer
Dim vAmount As Variant
Dim intControls As Integer, intForms As Integer
Dim rst As DAO.Recordset
Dim fld As Field
Dim intCnt As Integer
Set rst = Me.Recordset
intForms = Forms.Count ' Number of open forms.
'Check if any forms are open
If intForms > 0 Then
' Loop thru all open forms looking for frmGLSum
For intI = 0 To intForms - 1
Set frm = Forms(intI)
Select Case frm.Name
'Populate form from query
Case "frmGLSum"
intCnt = 1
For Each fld In rst.Fields ' Print field names.
Select Case VarType(fld.Value)
Case 0 To 1 'Value is a Null or empty
'Debug.Print " Fld 01 "; intCnt; " Name "; fld.Name; " "; fld.Value
Me("Hdn" & intCnt) = fld.Name
Me("Col" & intCnt).ControlSource = fld.Name '""
More similar code to populate unbound fields.
End Select
intCnt = intCnt + 1
Next
intCnt = 1
End Select
Next intI
Else
MsgBox "No open forms.", vbExclamation, "Form Controls"
'End check for any forms open
End If
End Sub