0

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

1 Answer 1

1

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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.