|
3#
楼主 |
发表于 2015-10-26 20:32:01
|
只看该作者
谢谢版主的耐心指点,所建议的刘晓军例子自己先搜下学习下。
自己的要求的确需要增加Form_Load时间代码(也比较复杂)。
不过,你给的如下代码可以完全满足自己的期望,从学习角度来说也是不错的例子,消化中。
不懂再来请教,非常感谢!
Option Compare Database
Private Sub Combo0_AfterUpdate()
Dim qry As DAO.QueryDef
Set qry = CurrentDb.QueryDefs("查询1")
If Me.Combo0 = "全部" Then
qry.SQL = "SELECT region FROM Data"
Else
qry.SQL = "SELECT region FROM Data where region='" & Me.Combo0 & "'"
End If
Me.child.SourceObject = "查询.查询1"
Me.Text3 = Me.child.Form.Recordset.RecordCount
End Sub
Private Sub Form_Load()
Dim rst As New ADODB.Recordset
Dim strSource As String
rst.Open "SELECT DISTINCT region FROM Data ORDER BY region", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
strSource = rst.GetString(, , , ";")
rst.Close
Me.Combo0.RowSourceType = "Value List"
Me.Combo0.RowSource = strSource & "全部;"
End Sub
|
|