我有一个Crosstab参数查询(XQryOxPara)从表格(FrmGlazes)中的组合框(CBglaze)获取其参数值
此参数查询用作另一个表单(FrmGlazes2)的记录源。第二种形式放在第一种形式,每当在FrmGlazes中选择新的釉料时,FrmGlazes2会更新。它大部分时间都可以正常工作
TblGlazes有一个gid(主键自动编号),釉(文本),31个其他数字字段,其中包含釉料成分的值。每个釉料都有一个记录。
TblOxides有oid(主键,自动编号),gid,glaze,subglaze(识别釉下名称的文本),16个其他数字字段,其中包含每个釉的氧化物成分的值。每个釉料有多个记录。
我的问题涉及:
例如,如果我选择TblGlazes但不是TblOxides的bg1_more_alumina,则生成的查询数据表视图为空。 但是,如果我选择bg1(在TblGlazes和TblOxides中),它会输入正确的信息。
我想要做的是将FrmGlazes2格式化为空白,如果在FrmGlazes中选择了釉面时没有记录显示。但由于记录集没有显示为空,我无法为该实例编写代码。因此,如果我使用当前事件中的以下代码,我就不会弹出任何消息框。它只是没有运行。但它确实针对其他实例运行,并向我显示所有相关信息
这是放在子窗体的On_Current事件中:
Private Sub Form_Current()
Dim dbs As Database
Dim qdf As QueryDef
Dim fld As Field
Dim rst As Recordset
Dim ColCount As Integer
Dim RowCount As Integer
Dim frm As Form
Dim frm2 As Form
Dim arr1() As Variant
Dim arr2() As Variant
Dim coltot As Single
Dim I As Integer
Dim J As Integer
Dim ctlname As String
Dim ctl As Control
Set dbs = CurrentDb
Set frm = Forms!FrmGlazes
Set qdf = dbs.QueryDefs!XQryOxPara
qdf.Parameters("Forms!FrmGlazes!Cbglaze") = frm![Cbglaze] 'Must go before set rst statement
Set rst = qdf.OpenRecordset()
' Hiding records based on whether values exist in field
' ------------------------------------------------------
If rst.EOF Then GoTo ErrNoRecords
ReDim Preserve arr1(0 To 0)
ReDim Preserve arr2(0 To 0)
With rst
Do Until .EOF
For Each fld In .Fields
If fld.Name <> "glaze" And fld.Name <> "Oxide" Then
J = fld.OrdinalPosition - 2
Debug.Print "val of J is: " & J & "Field Name: " & fld.Name
arr1(J) = arr1(J) + Nz(.Fields(fld.Name).Value)
arr2(J) = fld.Name
ReDim Preserve arr1(UBound(arr1) + 1)
ReDim Preserve arr2(UBound(arr2) + 1)
Debug.Print "arr1 value is: " & arr1(J)
End If
Next fld
.MoveNext
Loop
End With
ReDim Preserve arr1(UBound(arr1) - 1)
ReDim Preserve arr2(UBound(arr2) - 1)
Debug.Print "ub arr1 & arr2 are: " & UBound(arr1) & vbTab & UBound(arr2)
For I = 0 To J
ctlname = "Ctl" & arr2(I)
Me.Controls(ctlname).ColumnHidden = 1
Debug.Print "Ctlname is: " & ctlname & "arr1 value is: " & arr1(I)
If arr1(I) = 0 Then
Me.Controls(ctlname).ColumnHidden = -1
ElseIf arr1(I) > 0 Then
Me.Controls(ctlname).ColumnHidden = 0
End If
Next I
qdf.Close
rst.Close
dbs.Close
Set qdf = Nothing
Set rst = Nothing
Set fld = Nothing
Set dbs = Nothing
Exit Sub
ErrNoRecords:
qdf.Close
rst.Close
dbs.Close
Set qdf = Nothing
Set rst = Nothing
Set fld = Nothing
Set dbs = Nothing
End Sub
我的查询代码如下:
PARAMETERS [Forms]![FrmGlazes]![Cbglaze] Text ( 255 );
TRANSFORM Max(QryOx.Oxvalue) AS MaxOfOxvalue
SELECT QryOx.glaze, QryOx.Oxide
FROM QryOx
WHERE ((QryOx.glaze)=[Forms]![FrmGlazes]![Cbglaze]) OR (([Forms]![FrmGlazes]![Cbglaze]) Is Null)
GROUP BY QryOx.glaze, QryOx.Oxide
ORDER BY QryOx.glaze DESC
PIVOT QryOx.subglaze In ("30","30_21","30_22","30_23","302");
这是qryOx的代码
SELECT TblOxides.subglaze, "cobalt" As Oxide, cobalt As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where cobalt Is Not Null And cobalt>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "copper" As Oxide, copper As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where copper Is Not Null And copper>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "cocarb" As Oxide, cocarb As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where cocarb Is Not Null And cocarb>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "cucarb" As Oxide, cucarb As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where cucarb Is Not Null And cucarb>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "grilmenite" As Oxide, grilmenite As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where grilmenite Is Not Null And grilmenite>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "ilmenite" As Oxide, ilmenite As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where ilmenite Is Not Null And ilmenite>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "mio" As Oxide, mio As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where mio Is Not Null And mio>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "mndiox" As Oxide, mndiox As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where mndiox Is Not Null And mndiox>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "nickel" As Oxide, nickel As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where nickel Is Not Null And nickel>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "rio" As Oxide, rio As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where rio Is Not Null And rio>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "rutile" As Oxide, rutile As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where rutile Is Not Null And rutile>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "titdiox" As Oxide, titdiox As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where titdiox Is Not Null And titdiox>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "tin" As Oxide, tin As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where tin Is Not Null And tin>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "yio" As Oxide, yio As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where yio Is Not Null And yio>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "yochre" As Oxide, yochre As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where yochre Is Not Null And yochre>0
Order By glaze
UNION ALL SELECT TblOxides.subglaze, "zircon" As Oxide, zircon As Oxvalue, TblOxides.glaze, TblOxides.gid
From TblOxides
Where zircon Is Not Null And zircon>0
ORDER BY glaze;