2010-04-22 48 views
0

自從安裝Office 2007以來,我們的VBA應用程序代碼停止工作。當我調試時,我得到一個編譯錯誤,並且.edit被突出顯示。我用.update取代了.edit,我沒有得到任何調試錯誤,但是當我運行代碼時,我得到了一個類型不匹配的錯誤代碼。我做錯了什麼?這裏是codez:安裝Office 2007後VBA應用程序出現問題

Private Sub Command290_Click() 

對錯誤轉到Err_Command290_Click 「這個程序導入了最新的Changepoint CSV文件導入的ChangepointCSV表。 'SR:有效的日常

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 

' 設置默認值 一系列mydb = CurrentDb strExistingCSVTable = 「ChangepointCSV」

「形式的維護來限制用戶選擇 DoCmd.Close acForm, 「frmMain」,acSaveNo DoCmd.OpenForm 「frmImportingCPData」

( 「之前設置RS」) '獲取現有CSV文件 名' MSGBOX 設置rstAsOfDate = myDB.OpenReco rdset( 「tblChangepointFileName」) 'MSGBOX( 「後RS集」)

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

rstAsOfDate.Close 

' 獲得文件的名稱將要導入 FullFileName =的GetFile() 「MSGBOX( 「DEBUG FullFileName =」 + FullFileName)

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

「比較現有的以最新 如果strOldDate = FullFileName然後 MSGBOX 「的RI目前包含了最新的Changepoint數據提取。」 deleteBackup =假 轉到RestoreForms 結束如果

'如果的Changepoint CSV表存在,那麼將其備份的情況下的誤差的 tableExists = ObjectExists_20%( 「表」,strExistingCSVTable)

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

' 傳遞最新的CSV文件 transferSuccessful = TransferSpreadsheetFile(strExistingCSVTable,FullFileName) 'MsgBox(「DEBUG:Transfer Successful:」+ transferSuccessful)

'如果最新的CSV文件沒有被導入,恢復備份CSV並退出, 'else繼續處理。

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 

「恢復主窗體和清理備份文件 RestoreForms: 如果deleteBackup = TRUE,則 DoCmd.DeleteObject能夠作用, 「ChangepointCSV的備份」 結束如果

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

Exit_Command290_Click: 退出子

Err_Command290_Click: MSGBOX錯誤。Description Resume Exit_Command290_Click End Sub

+0

有兩種不同的'.Edit'部分在該代碼。哪一個被標記爲錯誤? – barrowc 2010-04-23 06:01:54

回答

1

我的第一個猜測是引用問題。您是否使用DAO或ADO進行數據訪問?檢查完您的參考後,如果使用DAO和ADODB.Database(如果使用ADO),請嘗試將DIM線更改爲DAO.Database等。

由於DAO和ADO都包含.Database對象VBA有時會感到困惑,以你的意思是其中之一,並從版本從內存的默認更改版本

相關問題