Importing ODBC excel file

2 posts / 0 new
Last post
Joined: 07/01/2019 - 06:38
Importing ODBC excel file

Hey Brian.I am trying to prepare a script which lets user to open a excel file with ODBC. I uploaded my sample excel and this is my code so far. I looked some of your codes in different examples but I couldn't achieve the result. I am getting an error at  ";DefaultDir=" part which wants me to  specify folder location. There is a syntax error at that part. Any help is appreciated. Have a nice day.
Dim sFilename As String
Dim workingFolder As String
Sub Main
       workingFolder = client.WorkingDirectory
       Call selectFile()
       Call ODBCImport()'
End Sub
Function selectFile()
      Dim opendlg As Object
      Set opendlg = CreateObject("Ideaex.SaveOpenDialog")
     Opendlg.DisplayDialog false
      sFilename = opendlg.SelectedFile
End Function
' File - Import Assistant: ODBC
Function ODBCImport
      Dim statement As Boolean
      statement = TRUE
      Dim i As Integer
      i = Len(sFilename)
          If Mid(sFilename,i,1) = "\" Or i < 0 Then
                statement = FALSE
           End If
           i = i - 1
       Loop While statement = TRUE
       MsgBox Mid(sFilename,1,i)
       dbName = "Sheet6$1.IMD"
       Client.ImportODBCFile "`Sheet6$`", dbName, FALSE, ";DSN=Excel Files; DBQ="&sFilename&";DefaultDir="&Mid(sFilename,1,i)&                          ";DriverId=1046;MaxBufferSize=2048;PageTimeout=5;" , "Select " & Chr(34) & "CURRENCY#ATTRIBUTE:KOD" & Chr(34) & ", " & Chr(34) & "CURRENCY#FOREXBUYING"           & Chr(34) & ", " & Chr(34) & "CURRENCY#FOREXSELLING#ELEMENT:TEXT" & Chr(34) & " FROM `Sheet6$`"
      Client.OpenDatabase (dbName)
End Function

Joined: 07/01/2019 - 06:38

Solved. I put a space after first & and it worked.