简而言之:我正在为我的客户端制作一个调度程序,由于受到限制,它需要在一个excel文件中(尽可能小).因此,一个工作表作为UI工作,其他任何工作表将是表或设置.
我正在尝试使用SQL(我是新手)来处理单个工作表(名为"TblEmpDays")上的计划数据.所以我需要在此工作表中添加/更新和检索记录.我能够获得一个 我正在使用VBA来编写所有这些,并且我创建了一个SQL帮助程序类,以使查询执行更容易. 为了澄清,我的问题是:我如何构建 类SQL: 执行功能: 我看了一遍都找不到解决办法.我确定我没有搜索过正确的短语或简单的东西.SELECT
查询来处理一些任意数据(并粘贴到一个范围).但是,我无法上班INSERT
或UPDATE
上班.我看到它的结构为INSERT INTO [
$] (
INSERT
和UPDATE
查询?我错过了什么?我想尽可能多地发布相关信息,所以如果我错过任何内容,请告诉我.Private pCn ' As Database
Private pResult 'As Recordset
Private pSqlStr As String
Public Property Get Result()
Result = pResult
End Property
Public Function Init()
Set pCn = CreateObject("ADODB.Connection")
With pCn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 12.0 Macro;HDR=YES;ReadOnly=False"";"
.Open
End With
End Function
Public Function Cleanup()
If Not (pCn Is Nothing) Then
pCn.Close
Set pCn = Nothing
End If
If Not pResult Is Nothing Then
Set pResult = Nothing
End If
End Function
Public Function CopyResultToRange(rg As Range)
If Not rg Is Nothing And Not pResult Is Nothing Then
rg.CopyFromRecordset pResult
End If
End Function
Public Property Get query() As String
query = pSqlStr
End Property
Public Property Let query(value As String)
pSqlStr = value
End Property
Public Function Execute(Optional sqlQuery As String)
If sqlQuery = "" Then
sqlQuery = query
End If
If Not pCn Is Nothing Then
Set pResult = pCn.Execute(sqlQuery, , CommandTypeEnum.adCmdText Or ExecuteOptionEnum.adExecuteNoRecords)
Else
MsgBox "SQL connection not established"
End If
End Function
Dim s As SQL ' this is the SQL class '
Dim tbl As String
' rcDay=date string, rcIn & rcOut = time strings, rcVac=boolean string, rcSls=number string'
Dim rcName As String, rcDay As String, rcIn As String, rcOut As String, rcVac As String, rcSls As String
Dim qry As String
tbl = "[TblEmpDays$]"
qry = "INSERT INTO
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有