Reputation: 187
Im using visual basic and visual studio 2010.
I researched on importing csv files to access database and I found this generic codes. The problem is, I'm really new in visual basic. I declared the variables but I got the error: "Declaration expected".. and the Do while and Loop are having an error which is: "Statement cannot appear outside of a method
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
Upvotes: 0
Views: 893
Reputation: 96
The first thing I see is that no method or subroutine has been declared.
That is essential.
How about declaring a Main
like this:
Public Class Form1
Sub Main()
Dim strPathFile As String
Dim strFile As String
...
End Sub
End Class
This will give your application a staring point.
May I suggest MSDN - Microsoft Developer Network - specifically the video walk through labelled "Visual Basic Fundamentals: Development for Absolute Beginners".
Upvotes: 1