Ms access 在运行时版本中运行数据库时出现错误
我已经完成了数据库的创建,它在我的计算机上运行得非常好。我使用的是access 2013,在我的VBA代码中,我为大多数数据库中使用的每个函数/子函数编写了错误处理程序。 但是,它的设计对象是访问运行时2007的用户,每次我在他们的机器上运行它时,我都会收到一个未捕获的错误“由于运行时错误,此应用程序的执行已停止” 命令按钮的代码 选项比较数据库Ms access 在运行时版本中运行数据库时出现错误,ms-access,Ms Access,我已经完成了数据库的创建,它在我的计算机上运行得非常好。我使用的是access 2013,在我的VBA代码中,我为大多数数据库中使用的每个函数/子函数编写了错误处理程序。 但是,它的设计对象是访问运行时2007的用户,每次我在他们的机器上运行它时,我都会收到一个未捕获的错误“由于运行时错误,此应用程序的执行已停止” 命令按钮的代码 选项比较数据库 Private Sub Command0_Click() Dim ErrorStep As String DoCmd.SetWarnings F
Private Sub Command0_Click()
Dim ErrorStep As String
DoCmd.SetWarnings False
'-------------------------------------------------------------------------------------
' Procedure : Command0_Click
' Author : Chris Sparkes
' Date : 13/08/2013
'-------------------------------------------------------------------------------------
ErrorStep = "1 - Cleansing Records"
DoCmd.OpenQuery "qry1_3"
DoCmd.OpenQuery "qry4-7"
DoCmd.OpenQuery "qry9"
Call ExcelOutputReport
Exit_Command0_Click:
On Error GoTo 0
Exit Sub
Command0_Click_Error:
MsgBox "Error in procedure Command0_Click of VBA Document."
GoTo Exit_Command0_Click
On Error GoTo 0
End Sub
Public Function ExcelOutputReport()
Dim ErrorStep As String
DoCmd.SetWarnings False
'---------------------------------------------------------------------------------------
' Procedure : ExcelOutputReport
' Author : Chris Sparkes
' Date : 13/08/2013
'---------------------------------------------------------------------------------------
ErrorStep = "1 - Cleansing Records"
Dim dbLocal As DAO.Database
Dim tbloutput As DAO.Recordset
'DAO Declarations
Dim objExcel As New Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objWorksheet As Excel.Worksheet
Dim IntCurrTask As Integer
Dim blurb As String
Set dbLocal = CurrentDb()
Set tbloutput = dbLocal.OpenRecordset("tbl_output")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("G:\Enliven Sales Report\Envliven_Report_Template_1.xls")
Set objWorksheet = objWorkbook.Worksheets("Enliven")
objExcel.Visible = True
objWorkbook.Windows(1).Visible = True
tbloutput.MoveFirst
IntCurrTask = 2
Do While Not tbloutput.EOF
With objWorksheet
.Cells(IntCurrTask, 1).Value = tbloutput![CustomerOrderCode]
.Cells(IntCurrTask, 2).Value = tbloutput![CustomerCode]
.Cells(IntCurrTask, 3).Value = tbloutput![CustomerDescription]
.Cells(IntCurrTask, 4).Value = tbloutput![ItemCode]
.Cells(IntCurrTask, 5).Value = tbloutput![ItemDescription]
.Cells(IntCurrTask, 6).Value = tbloutput![DateOrderPlaced]
.Cells(IntCurrTask, 7).Value = tbloutput![CustomerDueDate]
.Cells(IntCurrTask, 8).Value = tbloutput![Quantity]
.Cells(IntCurrTask, 9).Value = tbloutput![ShippedQuantity]
End With
IntCurrTask = IntCurrTask + 1
tbloutput.MoveNext
Loop
tbloutput.Close
dbLocal.Close
DoCmd.SetWarnings True
Set tbloutput = Nothing
Set dbLocal = Nothing
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = Nothing
Exit_ExcelOutputReport:
On Error GoTo 0
Exit Function
ExcelOutputReport_Error:
MsgBox "Error at in procedure ExcelOutputReport of VBA Document."
GoTo Exit_ExcelOutputReport
End Function
有人知道这是什么原因吗?这些引用应该是很好的,因为我使用的是我所知道的与我制作的不同数据库一起使用的那些引用
谢谢,
Chris您添加了错误例程,但未激活它们。在方法的开头,添加一条关于错误转到的
语句:
Private Sub Command0_Click()
On Error Goto Command0_Click_Error
...
End Sub
Public Function ExcelOutputReport()
On Error Goto ExcelOutputReport_Error
...
End Sub
在错误例程中,您应该(至少)显示Err.Description
的内容,而不是一般错误消息。否则,您将很难跟踪错误的来源。例如:
MsgBox "Error in procedure Command0_Click: " & Err.Description
我建议您启用警告(注释掉SetWarnings false)并重试。很遗憾,似乎没有进行任何更改。您能否向我们展示查询和代码的其余部分(函数ExcelOutputReport)?!Access运行时有时会崩溃,即使使用常规版本的Access运行的代码完全相同。它看起来不像常规版本那么稳定。嗯,我想任何人都看不到Command0()中的任何内容有任何问题?谢谢!好的,这很有效,很明显这是Command0_click()中的一个错误。我会看看这个,然后试着解决它。再次感谢。