在ACCESS如何批量执行 UPDATE 语句,这些语句有上百条,先放到ACCESS表格里.实现按顺序依次执行。
3个回答
展开全部
请看下面例子,这是我写的一个通用保存模块
Public Function SaveData(strSQL As String)
' On Error GoTo Err_SaveData
Dim rst As DAO.Recordset
Dim ctl As Control
Dim fld As Object
If MsgBox("您确认要保存吗?", vbOKCancel + vbInformation, "提示!!!") = vbOK Then
If AddTag = True Then
Set rst = CurrentDb.OpenRecordset(strSQL, , dbReadOnly)
rst.AddNew
Else
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.Edit
End If
For Each ctl In ctlFormName
'Debug.Print ctl.Name
If Not (TypeOf ctl Is Label Or TypeOf ctl Is CommandButton) Then
For Each fld In rst.Fields
'Debug.Print fld.Name
If fld.Name = ctl.Name Then
rst(fld.Name) = ctl
Exit For
End If
Next
End If
Next
rst.Update
rst.Close
Set rst = Nothing
MsgBox "数据保存成功!", vbInformation, "提示!!!"
End If
Exit_SaveData:
Set rst = Nothing
Exit Function
Err_SaveData:
If Err = 3022 Then
MsgBox "同一节点下不能存在相同的子节点,请修改后再点保存!", vbCritical, "警告!!!"
Else
MsgBox Err.Source & " #" & Err & vbCrLf & vbCrLf & Err.Description, vbCritical
On Error Resume Next
End If
Resume Exit_SaveData
End Function
Public Function SaveData(strSQL As String)
' On Error GoTo Err_SaveData
Dim rst As DAO.Recordset
Dim ctl As Control
Dim fld As Object
If MsgBox("您确认要保存吗?", vbOKCancel + vbInformation, "提示!!!") = vbOK Then
If AddTag = True Then
Set rst = CurrentDb.OpenRecordset(strSQL, , dbReadOnly)
rst.AddNew
Else
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.Edit
End If
For Each ctl In ctlFormName
'Debug.Print ctl.Name
If Not (TypeOf ctl Is Label Or TypeOf ctl Is CommandButton) Then
For Each fld In rst.Fields
'Debug.Print fld.Name
If fld.Name = ctl.Name Then
rst(fld.Name) = ctl
Exit For
End If
Next
End If
Next
rst.Update
rst.Close
Set rst = Nothing
MsgBox "数据保存成功!", vbInformation, "提示!!!"
End If
Exit_SaveData:
Set rst = Nothing
Exit Function
Err_SaveData:
If Err = 3022 Then
MsgBox "同一节点下不能存在相同的子节点,请修改后再点保存!", vbCritical, "警告!!!"
Else
MsgBox Err.Source & " #" & Err & vbCrLf & vbCrLf & Err.Description, vbCritical
On Error Resume Next
End If
Resume Exit_SaveData
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
新建多个更新查询,做一个宏组(选择多个OpenQuery,查询名称分别为之前建立的更新查询名称),然后在按钮里执行宏组就行了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用VBA----循环从记录集取出SQL语句,然后执行
docmd.runsql rst("sql语句")
docmd.runsql rst("sql语句")
追问
能给写得具体点吗?
追答
大概的写一下
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset("SQL语句表")
rst.movefirst
do Until rst.EOF
docmd.runsql rst("sql字段")
rst.movenext
Loop
rst.Close
Set dbs = Nothing
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询