Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here is your code modified - with comments. I have not tested the code completely, but it should work. (looks like June beat me...again )
    Instead of hardcoding the filenames/tables names I would have the names in a table and load them each time...


    Also I would use the system status message area to display which file was imported. That way you don't have to hit enter each time for the message box.


    Code:
    Sub txtImportstring()
       Dim strFilter As String
       Dim SourceFolder As String
       Dim strFolderName As String
       Dim InputSpec As String
    
       Dim i As Integer
       Dim LB As Integer
       Dim UB As Integer
    
       Dim strtblname   'array
       Dim strInputFileName  'array  
       '------------------
    
       ' arrays
       strtblname = (Array("Address_Information", "Portfolio_Manager_Section", "Fund_Strategy_Section", "Risk_Management", "Service_Providers", "Investment_Desicion", "Supporting Documents"))
       strInputFileName = (Array("Address Information.CSV", "Portfolio Manager Section.CSV", "Fund Strategy Section.CSV", "Risk Management.CSV", "Service Providers.CSV", "Investment Desicion.CSV", "Supporting Documents.CSV"))
    
       'upper & lower array bounds - ie how many elements in the array "strtblname"?
       LB = LBound(strtblname)
       UB = UBound(strtblname)
    
       'folder where the csv files are located
       SourceFolder = GetFolder()
    
       InputSpec = "actextTypeCSV12"
    
       For i = LB To UB
          If Len(strInputFileName(i)) > 0 Then
             'create the string
             strFolderName = SourceFolder & "\" & strInputFileName(i)
    
             DoCmd.TransferText acImportDelim, InputSpec, strtblname(i), strFolderName, True
    
             'tell which file was imported.
             'problem with MsgBox is action is required to continue
             MsgBox "Imported " & strtblename(i)
          End If
    
       Next
    
    Import_Exit:
       Exit Sub
    
    Import_Err:
       MsgBox Error$
       Resume Import_Exit
    End Sub
    
    
    Function GetFolder()
    Dim SA As Object
    Dim f As Object
    Set SA = CreateObject("Shell.Application")
    Set f = SA.BrowseForFolder(0, "choose a folder", 16 + 32 + 64)
    If (Not f Is Nothing) Then
        GetFolder = f.items.Item.Path
    End If
    Set f = Nothing
    Set SA = Nothing
    End Function

  2. #17
    mike02 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    245
    thanks steve! That works !!!

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

Similar Threads

  1. partial import with transfertext
    By hklein in forum Programming
    Replies: 2
    Last Post: 04-20-2012, 04:15 AM
  2. use vbs and TransferText cmd to import csv
    By conway in forum Import/Export Data
    Replies: 1
    Last Post: 02-03-2012, 08:38 PM
  3. TransferText
    By za20001 in forum Import/Export Data
    Replies: 1
    Last Post: 01-03-2012, 11:57 AM
  4. TransferText problem
    By rossib in forum Import/Export Data
    Replies: 1
    Last Post: 12-17-2009, 04:57 PM
  5. DoCmd.TransferText only if file is new
    By Coolpapabell in forum Programming
    Replies: 1
    Last Post: 10-14-2009, 01:57 AM

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