Function GetSql(sqlname as string) as string
'功能:得到SQL语句
'示例:msgbox GetSql("统计查询")
Dim Qdef As QueryDef
Set Qdef = CurrentDb.QueryDefs(sqlname)
GetSql = Qdef.SQL
Qdef.Close
Set Qdef = Nothing
End Function作者: fxbianxiu 时间: 2011-6-27 13:48
把上面的代码改一下就完事了嘛:
1、修改查询:
Function UpSql(sqlname as string,ssql as string)
'功能:修改SQL语句
'示例:call UpSql("名单查询","select * from 部门ID=" & me.部门ID.value)
Dim Qdef As QueryDef
Set Qdef = CurrentDb.QueryDefs(sqlname)
Qdef.SQL=ssql
Qdef.Close
Set Qdef = Nothing
End Function
2、创建查询:
Function CrtSQL(strname As String, ssql As String)
'功能:创建SQL语句
'示例:call CrtSql("名单查询","select * from 部门ID=" & me.部门ID.value)
Dim Qdef As QueryDef
Set Qdef = CurrentDb.CreateQueryDef(strname)
Qdef.SQL = ssql
Qdef.Close
Set Qdef = Nothing
End Function