|
6#
楼主 |
发表于 2014-6-10 16:14:16
|
只看该作者
Private Sub Command13_Click()
Dim db As Database
Dim qdf As QueryDefs
Set db = CurrentDb
S2 = "select "
For i = 0 To Me.List1.ListCount - 1
S2 = S2 & Me.List1.Column(0, i) & ","
Next i
S2 = Mid(S2, 1, Len(S2) - 1) & " from " & TabName & " where 井名='" & Forms![井数据查询].[Text0] & "'"
Dim tmp1 As String
temp1 = " select * from " & TabName & " where 井名='" & Forms![井数据查询].[Text0] & "'"
If S2 <> "select from " & " & TabName & " & " where 井名='" & Forms![井数据查询].[Text0] & "'" Then
On Error Resume Next
DoCmd.DeleteObject acQuery, "自动生成的查询"
Set qdf = db.CreateQueryDef("自动生成的查询", S2)
DoCmd.OpenQuery "自动生成的查询"
End If
Set db = Nothing
On Error Resume Next
DoCmd.DeleteObject acReport, "自动生成的查询"
DoCmd.RunCommand acCmdNewObjectAutoReport
DoCmd.Save acReport, "自动生成的查询"
DoCmd.Close acQuery, "自动生成的查询"
End Sub
我是这样添加的你的代码 但这样会同时打开查询和报表 直接删除 DoCmd.OpenQuery "自动生成的查询"还不可以 怎么改进好呢 |
|