【发布时间】:2011-05-26 03:46:33
【问题描述】:
我有一个查询驻留在访问文件 (.mdb) 中,我想在 VBA 中调用此查询,并将结果存储到现有表中。在插入结果之前,应该先删除表格的先前内容。
有什么想法吗?在我现有的代码中,查询名称“genInboundCdr”是通过 DoCmd.TransferSpreadsheet 执行的,结果存储到一个 excel 文件中。
Private Sub BtnExecuteQuery_Click()
If IsNull(txtOutputPath.value) Then
MsgBox "Please enter a valid output file location."
Else
If ObjectExists("Query", "genInboundCdr") Then
strPathToSave = txtOutputPath.value
MsgBox "About to extract inbound cdr..." & vbCrLf & _
"Please notice that the query may take longer time " & _
"( > 20 minutes ) if the linked tables contains a lot " & _
"of records."
txtStatus.value = txtStatus.value & _
"About to extract inbound cdr..." & vbCrLf & _
"Please notice that the query may take longer time " & _
"( > 20 minutes ) if the linked tables contains a lot " & _
"of records." & vbCrLf
DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, _
"genInboundCdr", _
strPathToSave, _
True
MsgBox ("Inbound Cdr generated.")
txtStatus.value = txtStatus.value & "Inbound Cdr generated." & vbCrLf
Else
MsgBox ("Query does not exist! Please review your steps.")
End If
End If
End Sub
【问题讨论】:
-
没有。它以访问形式执行。你误会了。它只会将结果生成到 excel 文件中。那没关系。现在我不想将结果存储在excel文件中,而是在访问文件中存储一个表。
-
你为什么要删除你的评论?这让我看起来像是在自言自语。
-
因为它不再相关。这里的人很聪明,可以理解!