簡體   English   中英

CSV文件導入以使用VBA訪問數據庫

[英]csv file import to access database using vba

我正在使用Visual Basic和Visual Studio 2010。

我研究了導入csv文件以訪問數據庫的過程,發現了這個通用代碼。 問題是,我在Visual Basic中真的是新手。 我聲明了變量,但是出現了錯誤:“期望聲明” ..而Do while和Loop出現錯誤,即:“語句不能出現在方法之外

Public Class Form1
    Dim strPathFile As String
    Dim strFile As String
    Dim strPath As String
    Dim strTable As String
    Dim blnHasFieldNames As Boolean

    blnHasFieldNames = True


    strPath = "C:\Users\vissia18\Desktop\ReportDB\"

    strTable = "Report"

    strFile = Dir(strPath & "*.csv")

    Do While Len(strFile) > 0
      strPathFile = strPath & strFile
      DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
            strTable, strPathFile, blnHasFieldNames

      strFile = Dir()
Loop
End Class

我看到的第一件事是尚未聲明任何方法或子例程。 那是必不可少的。 如何像這樣聲明Main

Public Class Form1
    Sub Main()
         Dim strPathFile As String
         Dim strFile As String
         ...
    End Sub
End Class

這將為您的應用程序提供一個起點。

我可以建議MSDN-Microsoft開發人員網絡 -特別是標記為“ Visual Basic基礎知識:絕對初學者的開發”的視頻。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM