【问题标题】:Error compiling VBA app after Office 2007 was installed安装 Office 2007 后编译 VBA 应用程序时出错
【发布时间】:2018-06-13 00:01:37
【问题描述】:

自从我们安装了 Office 2007 后,我们的 VBA 应用程序的代码就停止了工作。当我调试时,我得到一个编译错误,.Edit 被突出显示。我用.Update 替换了.Edit,我没有得到任何调试错误,但是当我运行代码时,我得到一个类型不匹配的错误代码。是不是我做错了什么?

代码如下:

Private Sub Command290_Click()
On Error GoTo Err_Command290_Click
'This routine imports the latest Changepoint CSV file into the ChangepointCSV table.
'SR: valid routine

    Dim FullFileName As String      'full file path & name
    Dim myDB As Database
    Dim rstAsOfDate As Recordset
    Dim rstCumulativeResources As Recordset
    Dim strOldDate As String
    Dim tableExists As Integer
    Dim strExistingCSVTable As String
    Dim transferSuccessful As String
    Dim deleteBackup As Boolean

'set default values
    Set myDB = CurrentDb
    strExistingCSVTable = "ChangepointCSV"

'form maintenance to restrict user options
    DoCmd.Close acForm, "frmMain", acSaveNo
    DoCmd.OpenForm "frmImportingCPData"

'get name of the existing CSV file
    'MsgBox ("before RS set")
    Set rstAsOfDate = myDB.OpenRecordset("tblChangepointFileName")
    'MsgBox ("after RS set")

    With rstAsOfDate
        'MsgBox ("inWITH")
       .Edit
        'Store original data.
        strOldDate = !CurrentFileName
    End With

    rstAsOfDate.Close

'get name of file to be imported
    FullFileName = GetFile()
    'MsgBox ("DEBUG  FullFileName = " + FullFileName)

    'FullFileName = "C:Documents and Settings ext.xlsx"

'compare existing to latest
    If strOldDate = FullFileName Then
        MsgBox "The RI currently contains the latest Changepoint data extract."
        deleteBackup = False
        GoTo RestoreForms
    End If

'if Changepoint CSV table exists then back it up in case of an error
    tableExists = ObjectExists_20%("Tables", strExistingCSVTable)

    If tableExists = -1 Then
        DoCmd.CopyObject , "ChangepointCSV-backup", acTable, strExistingCSVTable
        DoCmd.DeleteObject acTable, strExistingCSVTable
    End If

'transfer the latest CSV file
    transferSuccessful = TransferSpreadsheetFile(strExistingCSVTable, FullFileName)
    'MsgBox ("DEBUG:  Transfer Successful:  " + transferSuccessful)

'if the lastest CSV file was NOT imported, restore the backup CSV and exit,
'else continue processesing.

    If transferSuccessful = 0 Then
        DoCmd.CopyObject , strExistingCSVTable, acTable, "ChangepointCSV-backup"
        MsgBox "The Changepoint data could not be refreshed at this time.  Please try again later."
        deleteBackup = True
        GoTo RestoreForms:
    Else
        'MsgBox ("before RS set")
        Set rstAsOfDate = myDB.OpenRecordset("tblChangepointFileName")
        'MsgBox ("after RS set")

        'Update Filename
            With rstAsOfDate
                'MsgBox ("inWITH")
                .Edit
                'Store original data
                !CurrentFileName = FullFileName
                .Update
            End With

        rstAsOfDate.Close
        'MsgBox ("RS closed")

        Set rstCumulativeResources = myDB.OpenRecordset("tbl_CumulativeResources")
        Do While Not rstCumulativeResources.EOF
            rstCumulativeResources.Delete
            rstCumulativeResources.MoveNext
        Loop

        rstCumulativeResources.Close

        DoCmd.RunMacro "mcrFTEAnalysis"
        deleteBackup = True
        GoTo RestoreForms

    End If

'restores main form and cleans up backup file
RestoreForms:
    If deleteBackup = True Then
        DoCmd.DeleteObject acTable, "ChangepointCSV-backup"
    End If

    DoCmd.Close acForm, "frmImportingCPData", acSaveNo
    'MsgBox ("DEBUG:  import form closed")
    DoCmd.OpenForm "frmMain", acNormal

Exit_Command290_Click:
    Exit Sub

Err_Command290_Click:
    MsgBox Err.Description
    Resume Exit_Command290_Click
End Sub

【问题讨论】:

  • 该代码中有两个不同的.Edit 部分。哪个被标记为错误?

标签: vba office-2007


【解决方案1】:

我的第一个猜测是引用有问题。您是否使用 DAO 或 ADO 进行数据访问?检查您的参考文献后,如果使用 DAO,请尝试将 DIM 行更改为 DAO.Database 等;如果使用 ADO,请尝试将 DIM 行更改为 ADODB.Database。

因为 DAO 和 ADO 都包含一个 .Database 对象,所以 VBA 有时会混淆您的意思是哪个以及默认从内存中的版本到版本的变化

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    • 1970-01-01
    • 2015-09-26
    • 2021-08-01
    • 2012-01-31
    • 1970-01-01
    • 2018-01-02
    相关资源
    最近更新 更多