|
- Private Sub Command6_Click()
- Dim Qdf As DAO.QueryDef
- Dim varI As Variant
- Dim strGrp As String, strSum As String
- Dim strSQL As String, strGrpFldName As String
- For Each varI In Me.List0.ItemsSelected
- strGrp = strGrp & Me.List0.ItemData(varI) & ","
- Next
- For Each varI In Me.List2.ItemsSelected
- strSum = strSum & "Sum(" & Me.List2.ItemData(varI) & ") As 总" & _
- Me.List2.ItemData(varI) & ","
- Next
- If strGrp = "" Then
- MsgBox "请选择分组项目"
- Exit Sub
- ElseIf strSum = "" Then
- MsgBox "请选择统计项目"
- Exit Sub
- End If
- Set Qdf = CurrentDb.QueryDefs("B")
- strSum = Left(strSum, Len(strSum) - 1)
- strGrpFldName = Left(strGrp, Len(strGrp) - 1)
- strSQL = "select " & strGrp & strSum & " from a group by " & strGrpFldName
- Qdf.SQL = strSQL
- Me.Child4.SourceObject = "查询.b"
- Qdf.Close
- Set Qdf = Nothing
- End Sub
复制代码
增加一个动态生成行来源
Private Sub Form_Load()
Dim rs As New ADODB.Recordset
Dim strListTRowSource As String
Dim strListDRowSource As String
Dim i As Integer
With rs
.Open "A", CurrentProject.Connection, adOpenKeyset, adLockReadOnly
For i = 0 To .Fields.Count - 1
If .Fields(i).Type = 202 Then
strListTRowSource = strListTRowSource & .Fields(i).Name & ";"
ElseIf .Fields(i).Type = 3 Then
strListDRowSource = strListDRowSource & .Fields(i).Name & ";"
End If
Next
Me.List0.RowSourceType = "Value List"
Me.List2.RowSourceType = "Value List"
Me.List0.RowSource = strListTRowSource
Me.List2.RowSource = strListDRowSource
.Close
End With
Set rs = Nothing
End Sub
[ 本帖最后由 Henry D. Sy 于 2008-12-29 03:52 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|