J
John D
I have a Master Form, 6 subforms, and another subform on one of those subforms:
MASTER: FA1_OrgMaster
1st Sub: Fa1s5a_Services (and 5 others - things like locations, key
people, etc)
2nd Sub: FA1s5b_RptSrvcs (showing a crosstab query results)
On FA1_OrgMaster I have a Combo Box - cboOrgs - where user selects nonprofit
organization name. The 6 subforms are updated through the subform Link
Child/Master Fields properties.
But I can't get the 2nd Sub with the crosstab to "work".
The 2nd sub crosstab shows what services the nonprofit reported to the state
(the rows) in the previous 3 years (the columns). Next to that subform on
Fa1s5a_Services users will record other services they know the nonprofit
provides that are not reported to the state.
The SQL for the crosstab is:
TRANSFORM First(QOrg_S1_AllYrs_ServNumSort.Y_N) AS FirstOfY_N
SELECT QOrg_S1_AllYrs_ServNumSort.Service
FROM QOrg_S1_AllYrs_ServNumSort
WHERE (((QOrg_S1_AllYrs_ServNumSort.OrgID)=3000))
GROUP BY QOrg_S1_AllYrs_ServNumSort.Service, QOrg_S1_AllYrs_ServNumSort.OrgID
PIVOT QOrg_S1_AllYrs_ServNumSort.Year;
QOrg_S1_AllYrs_ServNumSort is a query on which this crosstab query is based.
In this case, the WHERE clause selects OrgID = 3000, a particular nonprofit.
What I want to do, in effect, is have that "3000" actually be whatever value
is in the cboOrgs Combo Box in the Master Form and have the crosstab display
updated whenever a new Org is chosen in cboOrgs.
I was refered to a solution for a crosstab as a subform created
programatically directly on a master form:
http://www.rogersaccesslibrary.com/OtherLibraries.asp#Hookom,Duane.
I adapted this code (as shown below). Glory be, it does change the
underlying crosstab query. But I can't figure out how to get the
FA1s5b_RptSrvcs to be updated when cboOrgs changes.
I've tried 5 or 6 things I can think of, and so far nothing works. These
include -
I can't figure out how to programatically create the dynamic crosstab as a
subform on the Services subform (much less how to position it on that
subform).
I've tried to get the 1st and 2nd subforms in synch by specifying the Link
Child Field as OrgID and the Master Field as cboOrgs, but a get an error
message that Access doesn't recognize OrgID as a valid field name. It
suggests I declare OrgID as a parameter and change the ColumnHeadings
Property - but OrgID is not a Column Heading in the crosstab. No go.
I can't seem to get the 2nd subform - FA1s5b_RptSrvcs - to be requeried in
the AfterUpdate property of cboOrgs.
Etc.
Here's how far I've gotten on the code:
_________
Private Sub cboOrgs_AfterUpdate()
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim strSQL As String
Dim strXTabQueryName As String
strXTabQueryName = "QFA1s4_AllYrs_ServNumSort_Crosstab"
Set db = CurrentDb
Set qd = db.QueryDefs(strXTabQueryName)
strSQL = "TRANSFORM First(QOrg_S1_AllYrs_ServNumSort.Y_N) AS FirstOfY_N"
& vbCrLf & _
"SELECT QOrg_S1_AllYrs_ServNumSort.Service" & vbCrLf & _
"FROM QOrg_S1_AllYrs_ServNumSort" & vbCrLf
If Not IsNull(Me.cboCounties) Then
strSQL = strSQL & "WHERE (QOrg_S1_AllYrs_ServNumSort.OrgID) = " &
[Forms]![FA1_OrgMaster_All]![cboOrgs] & vbCrLf
End If
strSQL = strSQL & " " & _
"GROUP BY QOrg_S1_AllYrs_ServNumSort.Service " & vbCrLf & _
"PIVOT QOrg_S1_AllYrs_ServNumSort.Year;"
qd.SQL = strSQL
Set qd = Nothing
Set db = Nothing
‘ Here’s why I’m stuck and have tried a bunch of things, including:
' Me.FA1s5b_SCOSrvcs.Requery
' Forms!FA1s5b_SCOSrvcs.SourceObject = "Query." & strXTabQueryName
‘ Etc
End Sub
____________
I'm working through 2 books on VBA in Access, but this is way beyond me
right now. Can you help?
Thanks
John D
MASTER: FA1_OrgMaster
1st Sub: Fa1s5a_Services (and 5 others - things like locations, key
people, etc)
2nd Sub: FA1s5b_RptSrvcs (showing a crosstab query results)
On FA1_OrgMaster I have a Combo Box - cboOrgs - where user selects nonprofit
organization name. The 6 subforms are updated through the subform Link
Child/Master Fields properties.
But I can't get the 2nd Sub with the crosstab to "work".
The 2nd sub crosstab shows what services the nonprofit reported to the state
(the rows) in the previous 3 years (the columns). Next to that subform on
Fa1s5a_Services users will record other services they know the nonprofit
provides that are not reported to the state.
The SQL for the crosstab is:
TRANSFORM First(QOrg_S1_AllYrs_ServNumSort.Y_N) AS FirstOfY_N
SELECT QOrg_S1_AllYrs_ServNumSort.Service
FROM QOrg_S1_AllYrs_ServNumSort
WHERE (((QOrg_S1_AllYrs_ServNumSort.OrgID)=3000))
GROUP BY QOrg_S1_AllYrs_ServNumSort.Service, QOrg_S1_AllYrs_ServNumSort.OrgID
PIVOT QOrg_S1_AllYrs_ServNumSort.Year;
QOrg_S1_AllYrs_ServNumSort is a query on which this crosstab query is based.
In this case, the WHERE clause selects OrgID = 3000, a particular nonprofit.
What I want to do, in effect, is have that "3000" actually be whatever value
is in the cboOrgs Combo Box in the Master Form and have the crosstab display
updated whenever a new Org is chosen in cboOrgs.
I was refered to a solution for a crosstab as a subform created
programatically directly on a master form:
http://www.rogersaccesslibrary.com/OtherLibraries.asp#Hookom,Duane.
I adapted this code (as shown below). Glory be, it does change the
underlying crosstab query. But I can't figure out how to get the
FA1s5b_RptSrvcs to be updated when cboOrgs changes.
I've tried 5 or 6 things I can think of, and so far nothing works. These
include -
I can't figure out how to programatically create the dynamic crosstab as a
subform on the Services subform (much less how to position it on that
subform).
I've tried to get the 1st and 2nd subforms in synch by specifying the Link
Child Field as OrgID and the Master Field as cboOrgs, but a get an error
message that Access doesn't recognize OrgID as a valid field name. It
suggests I declare OrgID as a parameter and change the ColumnHeadings
Property - but OrgID is not a Column Heading in the crosstab. No go.
I can't seem to get the 2nd subform - FA1s5b_RptSrvcs - to be requeried in
the AfterUpdate property of cboOrgs.
Etc.
Here's how far I've gotten on the code:
_________
Private Sub cboOrgs_AfterUpdate()
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim strSQL As String
Dim strXTabQueryName As String
strXTabQueryName = "QFA1s4_AllYrs_ServNumSort_Crosstab"
Set db = CurrentDb
Set qd = db.QueryDefs(strXTabQueryName)
strSQL = "TRANSFORM First(QOrg_S1_AllYrs_ServNumSort.Y_N) AS FirstOfY_N"
& vbCrLf & _
"SELECT QOrg_S1_AllYrs_ServNumSort.Service" & vbCrLf & _
"FROM QOrg_S1_AllYrs_ServNumSort" & vbCrLf
If Not IsNull(Me.cboCounties) Then
strSQL = strSQL & "WHERE (QOrg_S1_AllYrs_ServNumSort.OrgID) = " &
[Forms]![FA1_OrgMaster_All]![cboOrgs] & vbCrLf
End If
strSQL = strSQL & " " & _
"GROUP BY QOrg_S1_AllYrs_ServNumSort.Service " & vbCrLf & _
"PIVOT QOrg_S1_AllYrs_ServNumSort.Year;"
qd.SQL = strSQL
Set qd = Nothing
Set db = Nothing
‘ Here’s why I’m stuck and have tried a bunch of things, including:
' Me.FA1s5b_SCOSrvcs.Requery
' Forms!FA1s5b_SCOSrvcs.SourceObject = "Query." & strXTabQueryName
‘ Etc
End Sub
____________
I'm working through 2 books on VBA in Access, but this is way beyond me
right now. Can you help?
Thanks
John D