Question : Use varaible in Docmd.transfertext

Is it not possible to use a variable when using docmd.transfertext?  I'm using access 2000

I want the user to be able to pick where the csv file resides so I use the windows open dialog box and put the file path in the csvfilename variable.


here is the code I'm trying to execute

Private Sub cmdImportCSV_Click()

Call Module1.OpenCSVFile



DoCmd.TransferText acImportDelim, "Dialer_App Link Specification", "dbo_dialer_app", CSVFILENAME , False

'DoCmd.TransferText acImportDelim, "Dialer_App Link Specification", "dbo_dialer_app", "C:\DVS\dialer\dialer_list_test.csv", False
End Sub


In debug, I verfiy that variable CSVFILENAME contains C:\DVS\dialer\dialer_list_test.csv but it does not work.  I get a run-time error '3349'  Numeric field overflow.


If I comment that line of code and uncomment then execute the line with the path hard coded it works just fine.

Any ideas what i'm doing wrong?

Answer : Use varaible in Docmd.transfertext

I have a better thing for You.....


'Form code
'--------------
'Import csv File
Private Sub cmdImportcsvfile_Click()
Application.DoCmd.SetWarnings (False)
 Dim strCSV_File As String
   
    strCSV_File = GetCSV(Me)
   
    If strCSV_File = vbNullString Then GoTo GetstrCSV_File_exit
   
    On Error GoTo ErrInvalidProject
   
    DoCmd.SetWarnings (0)
   
 

    Application.DoCmd.TransferText acImportDelim, "CSVImport", "CSVRaw", strCSV_File, True

    DoCmd.SetWarnings (-1)
   
    MsgBox strCSV_File & " has been imported.", vbInformation, "Import - CSV"
 

GetstrCSV_File_exit:
        Exit Sub
   
ErrInvalidProject:
        MsgBox "Some problem is with the File", vbCritical, "Import - CSV"
       
End Sub




'generic module
'--------------------------
Option Compare Database
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As String
    lpstrCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As String
    nMaxFile As Long
    lpstrFileTitle As String
    nMaxFileTitle As Long
    lpstrInitialDir As String
    lpstrTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    lpstrDefExt As String
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As String
End Type

-----------
Function GetCSV(strform As Form) As String
    Dim OpenFile As OPENFILENAME
    Dim lReturn As String
    Dim sFilter As String
    OpenFile.lStructSize = Len(OpenFile)
    OpenFile.hwndOwner = strform.Hwnd
    sFilter = "CSV Files (*.csv)" & Chr(0) & "*.csv*"
    OpenFile.lpstrFilter = sFilter
    OpenFile.nFilterIndex = 1
    OpenFile.lpstrFile = String(257, 0)
    OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
    OpenFile.lpstrFileTitle = OpenFile.lpstrFile
    OpenFile.nMaxFileTitle = OpenFile.nMaxFile
    'OpenFile.lpstrInitialDir = "C:\"
    OpenFile.lpstrTitle = "Select File"
    OpenFile.flags = 0
    lReturn = GetOpenFileName(OpenFile)
   '     If lReturn = 0 Then
   '         MsgBox "A file was not selected!", vbInformation, _
   '           "Select a file using the Common Dialog DLL"
   '      Else
            GetCSV = Trim(Left(OpenFile.lpstrFile, InStr(1, OpenFile.lpstrFile, vbNullChar) - 1))
    '    End If
End Function





Random Solutions  
 
programming4us programming4us