Results 1 to 4 of 4
  1. #1
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13

    importing data if it's a certain filename

    Hey all,

    bit of a noob here, I'm trying to import data if it's worksheet is called 'Master' I eventually want to expand and if it's called 'Master' import and run these queries, if it's called redistributed then import and run these queries. Basically I'm importing to a new table, data clensing and then merging with the existing table. But I can't get it working and I'm stuck. Any help would be much appreciated. The errors I'm getting are the next and end with are in the wrong spot, eg. next without for, end with without with.

    Code:
    Private Sub Command0_Click()
        Dim fd As FileDialog
        Dim strfile As String
        Dim strsearchpath As String
        Dim vrtSelectedItem As Variant
        Dim strSql As String
        Dim SheetName As String:   SheetName = "Master"
        Dim wb As Workbook, ws As Worksheet
    
          
     Set myDialog = Application.FileDialog(msoFileDialogOpen)
     'Use strSearchPath  if you want to start in a particular directory. You can leave it out if you wish (as I have it commented out right now) and it will start with a default directory of Windows choosing.
     strsearchpath = "c:\"
     
     With myDialog
     
        .AllowMultiSelect = False
        .Filters.Add "Excel Files", "*.xlsx", 1
         .Title = "locate files"
         .InitialFileName = strsearchpath
         DoCmd.SetWarnings False
     
    If .Show = True Then
        For Each vrtSelectedItem In .SelectedItems
        'doublechecking file name
         MsgBox "file chosen = " & vrtSelectedItem
           'I pass the file information to another routine that handles the transfer
          
           
           
          If vrtSelectedItems.SheetExists(SheetName) Then
                DoCmd.TransferSpreadsheet acImport, , "importtable", vrtSelectedItem, True, SheetName
           Next vrtSelectedItem
           Else
           MsgBox "not master"
           
       
         End If
    
          End With
          
        
        ' delete blank rows
        strSql = "Delete FROM importtable Where Len(Trim([asset number] & ' '))=0 "
        'runSQL for strsql
        DoCmd.RunSQL (strSql)
         
         MsgBox "imported"
    
         
     
     End Function

    Last edited by token_remedie; 09-25-2011 at 04:54 PM. Reason: more info

  2. #2
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13

    sort of solved

    I fixed the first problem, if anyone is interested I did this:

    Code:
     With myDialog
     
        .AllowMultiSelect = False
        .Filters.Add "Excel Files", "*.xlsx", 1
         .Title = "locate files"
         .InitialFileName = strsearchpath
         DoCmd.SetWarnings False
     
    If .Show = True Then
        For Each vrtSelectedItem In .SelectedItems
        'doublechecking file name
         MsgBox "file chosen = " & vrtSelectedItem
           'I pass the file information to another routine that handles the transfer
               Next
                End If
                 End With
          If vrtSelectedItems.SheetExists(SheetName) Then
                DoCmd.TransferSpreadsheet acImport, , "importtable", vrtSelectedItem, True, SheetName
           
           Else
           MsgBox "not master"
              
         End If

    but now it's saying obbject required.....where am I going wrong there?

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    Have you considered using
    DoCmd.TransferSpreadsheet acImport.....
    directly? You could have a form or option group to select the "sheet" you want and run the Transferspreadsheet......

  4. #4
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13
    that is a REALLY good idea. *high five*
    Thanks orange

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Importing data into various tables
    By simba in forum Import/Export Data
    Replies: 1
    Last Post: 01-13-2011, 12:42 PM
  2. Importing .txt data
    By Redder Lurtz in forum Import/Export Data
    Replies: 4
    Last Post: 11-18-2010, 10:23 AM
  3. Importing data and data quality
    By fsmikwen in forum Import/Export Data
    Replies: 1
    Last Post: 02-01-2010, 03:15 PM
  4. importing data- find new data
    By cengineer in forum Import/Export Data
    Replies: 1
    Last Post: 12-10-2009, 08:56 AM
  5. Replies: 0
    Last Post: 06-11-2009, 01:54 PM

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