VBA创建查询/修改查询/执行操作查询
时间:2009-05-23 09:35 来源:网络 作者:UMVsoft整… 阅读:次
Sub CX() '最单的VBA创建查询例子
Dim strSQL As String
Dim qdf As QueryDef
'删除TEMP查询
For Each Query1 In CurrentDb.QueryDefs
If Query1.Name = "TEMP" Then
CurrentDb.QueryDefs.Delete Query1.Name
Exit For
End If
Next Query1
strSQL = "Select * from ZZ1" 'tblaa为表
Set qdf = CurrentDb.CreateQueryDef("TEMP", strSQL) '创建查询TEMP
DoCmd.OpenQuery qdf.Name '执行查询
End Sub
Dim strSQL As String
Dim qdf As QueryDef
'删除TEMP查询
For Each Query1 In CurrentDb.QueryDefs
If Query1.Name = "TEMP" Then
CurrentDb.QueryDefs.Delete Query1.Name
Exit For
End If
Next Query1
strSQL = "Select * from ZZ1" 'tblaa为表
Set qdf = CurrentDb.CreateQueryDef("TEMP", strSQL) '创建查询TEMP
DoCmd.OpenQuery qdf.Name '执行查询
End Sub
'//---------------------------------------------------------
Private Sub Command5_Click() '修改查询TMP的SQL
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Set db = CurrentDb
Set qry = db.QueryDefs("TMP")
SQL = "Select myvagn([08期中],[08期末],[09期中]) AS X总分X,学号, 性别, 姓名, 班级,[08期中],[08期末],[09期中]"
SQL = SQL + " FROM " & Me.Combo0 & "摸底 orDER BY myvagn([08期中],[08期末],[09期中]) DESC;"
qry.SQL = SQL
DoCmd.OpenQuery "TMP", acNormal, acEdit '运行查询
End Sub
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Set db = CurrentDb
Set qry = db.QueryDefs("TMP")
SQL = "Select myvagn([08期中],[08期末],[09期中]) AS X总分X,学号, 性别, 姓名, 班级,[08期中],[08期末],[09期中]"
SQL = SQL + " FROM " & Me.Combo0 & "摸底 orDER BY myvagn([08期中],[08期末],[09期中]) DESC;"
qry.SQL = SQL
DoCmd.OpenQuery "TMP", acNormal, acEdit '运行查询
End Sub
'//------------------------------------------------------------
Private Sub Command4_Click()' VBA执行查询 生成表
SQL = "Select [0xx中学结构].* INTO " & Me.Combo0
SQL = SQL + " FROM 0xx中学结构;"
DoCmd.RunSQL (SQL)
End Sub
SQL = "Select [0xx中学结构].* INTO " & Me.Combo0
SQL = SQL + " FROM 0xx中学结构;"
DoCmd.RunSQL (SQL)
End Sub
(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
相关内容
- ·关于 Partition 函数在分组查询中的应
- ·Access算术运算符的含义和说明表
- ·mid函数的另类用法
- ·access制作程序运行进度框
- ·Function与Sub的异同(函数调用)
- ·Access判断某个数值是否为某个数据类型
- ·select case后面语句块的值的四种格式
- ·vba条件语句的两种表示方法
- ·Access几种数据类型初始化的值
- ·Access vba null与""空字符串的区别
- ·access vba 数据类型表
- ·Access变量的命名规则
- ·Access中EXIT Sub与End Sub的区别
- ·Access vba中参数前关键字ByRef和ByVal
- ·Access列表框快速全选的技巧【最快】
- ·vba函数的数据类型强制转换
最新内容
推荐内容