Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68
    Following is the Vonage statement file to be imported. Note that the 2nd field is named "null" for some reason. My reference to "null" in the code (If strArray(1) <> "null" Then) is simply to exclude the Header row when importing the records.

    YY-MMDD.csv Downloaded File


    Date/Time,null,Number,Length,Cost
    12/20/2012 12:11 PM,Forwarded,BANK OF AMERICA (949) 994-7496,00:32,--
    12/20/2012 09:03 AM,Forwarded,BANK OF AMERICA (949) 994-7496,00:03,--
    12/14/2012 02:34 PM,Outgoing,(781) 975-7822,01:43,--
    12/14/2012 11:10 AM,Incoming,TOLL FREE CALL (866) 294-1503,00:09,--
    12/14/2012 10:15 AM,Outgoing,(708) 695-6619,00:14,--
    12/12/2012 11:41 AM,Incoming,TOLL FREE CALL (866) 854-3732,00:04,--

  2. #17
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I count 4 commas. That means you have 5 columns. Null is the header for the transaction type, eg Forwarded.

    I would not include
    (If strArray(1) <> "null" Then)

    Also, not sure what the integer 4 is doing in your Split function. I mean, I do not know what it represents. According to help files, there are two options 0 and 1 for Binary and Textual respectively. Do not know if it is an issue. I could not find a list of constants or even a help file specific to VBA and Access.

  3. #18
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68
    Correct, the file has 5 columns. However, the 5th column is always "--", and not needed. The Integer 4 in the Split Function limits it to 4 columns.
    Split(expression [, delimiter ] [, limit ] [, compare ] )
    The Split function syntax has these arguments:
    ARGUMENT DESCRIPTION
    expression Required. String expression containing substrings and delimiters. If expression is a zero-length string(""), Split returns an empty array, that is, an array with no elements and no data.
    delimiter Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing
    the entire expression string is returned.
    I've removed the Integer 4, and it makes no difference.

    When I remove (If strArray(1) <> "null" Then), only the Header row is imported. None of the actual records are imported.


    limit Optional. Number of substrings to be returned; –1 indicates that all substrings are returned.
    compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.

  4. #19
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I got it to work. I just need to fix the loop. It is not recognizing the file name. Give me a few.

  5. #20
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    THis is working. Once I got it into a VBA module intelisense told me that there are three arguments for Switch. So the integer 4 is counting the array.


    Code:
    Private Sub Command0_Click()
    
    'DoCmd.Hourglass True
    ' CurrentDb.Execute "DELETE * FROM VonageStmt;"
    ' lblVonageStmt.Visible = False
    ' txtVonageStmt = ""
     Dim rs1 As DAO.Recordset
     Dim FileName As String
     Dim FileDate As Date
     Dim FileNum As Integer
     Dim strFilter As String
     Dim strFileDesc As String
     Dim strFileExt As String
     Dim strRecord As String
     Dim strRecordArray() As String
     Dim intCount As Integer
     Dim InputString
     
    FileName = "C:\Test\SampleImport.csv"
    ' FileName = ahtCommonFileOpenSave( _
    ' InitialDir:="C:\Users\jhrAcer\Downloads\Vonage", _
    ' Filter:=strFilter, _
    ' OpenFile:=True, _
    ' DialogTitle:="Select File for Import... *.csv", _
    ' Flags:=ahtOFN_HIDEREADONLY)
    ' FileDate = FileDateTime(FileName)
    ' FileNum = FreeFile()
     Set rs1 = CurrentDb.OpenRecordset("VonageStmt")
    ' DoCmd.RepaintObject acForm, "FrmMainMenu"
    ' DoCmd.Hourglass True
    'Me.Command0.HyperlinkAddress = FileName
    Dim intFile As Integer
    intFile = FreeFile()
    Dim strMyChange As String
    ' Open FileName For Input As #FileNum
     Open FileName For Input As intFile
     
     
    ' On Error Resume Next
    Do Until EOF(intFile)
    
     Line Input #intFile, InputString
     strRecordArray = Split(InputString, ",", 4)
     If strRecordArray(1) <> "null" Then
     rs1.AddNew
     rs1.Fields("DtTm") = strRecordArray(0)
     rs1.Fields("Type") = strRecordArray(1)
     rs1.Fields("Number") = strRecordArray(2)
     
    strMyChange = Left(strRecordArray(3), InStr(strRecordArray(3), ",") - 1)
     rs1.Fields("Length") = strMyChange
     
     RecCnt = RecCnt + 1
     rs1.Update
     End If
    Loop
     rs1.Close
     Set rs1 = Nothing
     Close #intFile
    ' DoCmd.Hourglass False
    ' lblVonageStmt.Visible = True
    ' txtVonageStmt = RecCnt
     
    End Sub

  6. #21
    jhrBanker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2009
    Posts
    68
    It's working!!!!
    Many, many thanks!

  7. #22
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Sure. I would probably use another option like Paul mentioned eg the Import Wizard or something else but, sometimes parsing data before the DB sees it is best.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Run-Time Error 91 with import code
    By maxmd29 in forum Import/Export Data
    Replies: 30
    Last Post: 12-19-2013, 11:28 AM
  2. Replies: 6
    Last Post: 04-26-2013, 03:51 PM
  3. VBA Code to Import Excel Files
    By Rxp in forum Programming
    Replies: 2
    Last Post: 07-26-2012, 03:57 PM
  4. Replies: 1
    Last Post: 02-09-2012, 08:43 PM
  5. Code for data import with calculated field
    By Tyork in forum Programming
    Replies: 2
    Last Post: 01-21-2011, 03:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums