access二级考试题。。。求指教。。
Private Sub bt_Click()Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
Dim sage As Single
'设置当前数据库连接
Set cn = CurrentProject.Connection
strSQL = "select avg(年龄) from tEmp where 党员否"
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
'*****Add1*****
'*****Add1*****
MsgBox "无党员职工的年龄数据"
sage = 0
Exit Sub
Else
sage = rs.Fields(0)
End If
'*****Add2*****
'*****Add2*****
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
'以下是外部文件写入操作
If Dir(CurrentProject.Path & "\out.dat", vbDirection) <> vbNullString Then
Kill CurrentProject.Path & "\out.dat"
End If
Open CurrentProject.Path & "\out.dat" For Output As #1
Print #1, sage
Close #1
End Sub