将数据库导出到其他计算机时出错

时间:2012-04-06 18:23:54

标签: vba ms-access access-vba

我已经在安装程序中创建了一个数据库,该安装程序作为epos系统运行。

在其他计算机上安装它时,我收到大量错误,都说缺少某些东西。该文件在我的计算机上运行完美,但错误阻止了在其他计算机上工作....

错误如下。每个都有自己的弹出框。

broken reference to excel.exe version 1.7 or missing.
acwztool.accde missing
npctrl.dll v4.1 missing
contactpicker.dll v1.0 missing
cddbcontolwinamp.dll v1.0 missing
cddbmusicidwinamp.dll v1.0 missing
colleagueimport.dll v1.0 missing
srstsh64.dll missing

我觉得这可能是因为我改变了模块vba库引用,以便我可以运行使用excel的vba代码,不幸的是我忘记了我添加了哪些库?

如果有帮助,我添加的需要新引用的代码在

之下
Public Sub SalesImage_Click()
Dim rst As ADODB.Recordset

' Excel object variables
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlChart As Excel.Chart

Dim i As Integer

On Error GoTo HandleErr

' excel aplication created
Set xlApp = New Excel.Application

' workbook created
Set xlBook = xlApp.Workbooks.Add

' set so only one worksheet exists
xlApp.DisplayAlerts = False
For i = xlBook.Worksheets.Count To 2 Step -1
    xlBook.Worksheets(i).Delete
Next i
xlApp.DisplayAlerts = True

' reference the first worksheet
Set xlSheet = xlBook.ActiveSheet

' naming the worksheet
xlSheet.name = conSheetName

' recordset creation
Set rst = New ADODB.Recordset
rst.Open _
 Source:=conQuery, _
 ActiveConnection:=CurrentProject.Connection

With xlSheet
    ' the field names are imported into excel and bolded
    With .Cells(1, 1)
        .Value = rst.Fields(0).name
        .Font.Bold = True
    End With
    With .Cells(1, 2)
        .Value = rst.Fields(1).name
        .Font.Bold = True
    End With

    ' Copy all the data from the recordset into the spreadsheet.
    .Range("A2").CopyFromRecordset rst

    ' Format the data the numbering system has been extended to encompas up to 9,999,999 sales to cover all posibilities of sales since the last stock take
    .Columns(1).AutoFit
    With .Columns(2)
        .NumberFormat = "#,###,###"
        .AutoFit
    End With
End With

' Create the chart.
Set xlChart = xlApp.Charts.Add
With xlChart
    .ChartType = xl3DBarClustered
    .SetSourceData xlSheet.Cells(1, 1).CurrentRegion
    .PlotBy = xlColumns
    .Location _
     Where:=xlLocationAsObject, _
     name:=conSheetName
End With

'the reference must be regotten as it is lost
With xlBook.ActiveChart
    .HasTitle = True
    .HasLegend = False
    With .ChartTitle
        .Characters.Text = conSheetName & " Chart"
        .Font.Size = 16
        .Shadow = True
        .Border.LineStyle = xlSolid
    End With
    With .ChartGroups(1)
        .GapWidth = 20
        .VaryByCategories = True
    End With
    .Axes(xlCategory).TickLabels.Font.Size = 8
    .Axes(xlCategoryScale).TickLabels.Font.Size = 8
 End With

 With xlBook.ActiveChart
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Product"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Sales"
End With

 'format the size and possition of the chart
With xlBook.ActiveChart
    .Parent.Width = 800
    .Parent.Height = 550
    .Parent.Left = 0
    .Parent.Top = 0
End With

'this displays the chart in excel. excel must be closed by the user to return to the till system
xlApp.Visible = True

ExitHere:
On Error Resume Next
'this cleans the excel file
rst.Close
Set rst = Nothing
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Exit Sub

HandleErr:
MsgBox Err & ": " & Err.Description, , "There has been an error!"
Resume ExitHere

End Sub

1 个答案:

答案 0 :(得分:2)

如果删除项目的Excel引用并使用Excel对象的后期绑定,则部署应该不那么麻烦。

缺点是你在开发过程中失去了Intellisense的优势,并且后期绑定。但是,在开发期间的早期绑定和生产的后期绑定之间切换非常容易。只需更改编译器常量的值。

在模块的声明部分......

    #Const DevStatus = "PROD" 'PROD or DEV

然后在程序的主体内...

    #If DevStatus = "DEV" Then
        Dim xlApp As Excel.Application
        Dim xlBook As Excel.Workbook
        Dim xlSheet As Excel.Worksheet
        Set xlApp = New Excel.Application
    #Else ' assume PROD (actually anything other than DEV)
        Dim xlApp As Object
        Dim xlBook As Object
        Dim xlSheet As Object
        Set xlApp = CreateObject("Excel.Application")
    #End If

使用后期绑定,您的代码将需要使用Excel常量的值而不是常量名称。或者,您可以在#Else块中定义命名常量以供生产使用,然后继续在代码中按名称使用它们。

我不知道所有其他参考是什么。建议您获取项目的副本,删除所有这些引用,并查看从VB编辑器主菜单运行Debug->Compile时会发生什么。不选中任何不需要的引用。并尝试后期绑定其余部分。我在Access应用程序的生产版本中只使用了3个引用:VBA;访问;和DAO。

相关问题