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

    working with imported data

    Hi, I need some help with a query after I've imported data into Access.
    I've sucessfully imported the data locally but I need to be able to do it across a network, and once this is done, i want my query to:

    * match data by asset number in the new table to asset number in the existing main table (books)
    * if it finds a match copy that record from books to transactions(a history table)
    * delete the record from books and insert into from the newly imported table

    and do that for every record that's imported into the new table. I'll then be clearing the new table ready for next time it imports.

    here's my code:

    <code>

    Option Compare Database

    Private Sub Command0_Click()
    Dim strFile As String 'Filename
    Dim strFileList() As String 'File Array
    Dim intFile As Integer 'File Number
    Dim filename As String
    Dim path As String

    DoCmd.SetWarnings False
    'path = Application.CurrentProject.path & "\Import" locally works
    path = "Z:\Technologies\Projects\" ' network path that I'm trying to get working

    'Loop through the folder & build file list
    strFile = Dir(path & "*.xlsx")

    While strFile <> ""
    'add files to the list
    intFile = intFile + 1
    ReDim Preserve strFileList(1 To intFile)
    strFileList(intFile) = strFile
    strFile = Dir()
    Wend

    'see if any files were found
    If intFile = 0 Then
    MsgBox "Could Not Find File"
    Exit Sub
    End If

    'cycle through the list of files


    For intFile = 1 To UBound(strFileList)
    filename = Application.CurrentProject.path & "\" & strFileList(intFile)
    'DoCmd.TransferText acImportDelim, , "YOURTABLENAME", filename, False

    DoCmd.TransferSpreadsheet acImport, , "Tabletest", filename, True
    Next intFile

    DoCmd.SetWarnings True
    DoCmd.OpenQuery "matchedtest" 'query that finds matches between new table and existing main table
    'DoCmd.SetWarnings False
    'DoCmd.RunSQL "DELETE * FROM Tabletest"


    Dim SQL As String

    'here's where it's coming unstuck

    SQL = "SELECT Books.* FROM Books LEFT OUTER JOIN matchedtest ON matchedtest.[asset number] = Books.[asset number] WHERE Books.[asset number] = IS NOT NULL"

    If DCount("*", "matchedtest", "Books.[asset number]") < 1 Then

    'msg box so i know if the code is working

    MsgBox ("nothing to update")
    Exit Sub
    Else
    MsgBox ("updating")

    'string creation and insert


    SQL = "INSERT INTO Transactions([asset number])VALUES ('" & [Asset Number] & "')"

    End If


    CurrentDb.Execute SQL





    End Sub


    </code>


    Thank you in advance if you can tell me where I'm going wrong

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What is your question? What is the issue - error message, wrong results, nothing happens?

    BTW, use [] for CODE tags instead of <>.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13
    well firstly, how do i get it to import across a network instead of locally?

    and then after that data is imported im trying to compare by asset number to an existing table to tabletest is my imported data, and books is my main table then if it exists in books copy that record to transactions, delete it from books and insert the record from testtable to books, so that there's only one asset in books but its history is kept in transactions.

    thanks for the code[] tip, I always wondered why it never works for me haha

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    By network do you mean your office LAN? Can you map a drive designation to the location with Windows Explorer? Then should be simply naming that path in the code as you are doing. Actually, I prefer to use UNC (Universal Naming Convention). Instead of referring to location with drive letter, I use the server name, like: servername\\folders path\filename

    Again, need specifics. What is not working - error messages. Have you step debugged? What line errors?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13
    yeah across LAN,

    I got it to import by using full UNC name, which is great but it doesn't actually point where it's supposed to it's redirecting to the desktop.

    I put in MsgBox ("import" + filename + "?") to see what file name it's importing and it's pulling it from the desktop instead of the LAN location.

    if I rename or remove that file from my desktop it still asks if i want to import it and then says it can't find the file... so where is that filename stuck? :S

  6. #6
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13
    oh pffft nevermind i found it

  7. #7
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13
    ok so I decided to go a different way and I think it's way better (for everyone's sake) because if I'm importing I can select the file myself.... and if I leave here someone can easily take over.

    but I can't pass the filename to the import, any ideas?



    Code:
    Option Compare Database
    
    Private Sub Command0_Click()
        Dim strFile As String 'Filename
        Dim strFileList() As String 'File Array
        Dim intFile As Integer 'File Number
        Dim filename As String
        Dim path As String
        Dim f As Object
        
        Set f = Application.FileDialog(3)
            f.AllowMultiSelect = True
            f.show
        MsgBox "file chosen = " & f.selectedItems.Count
        
    
        DoCmd.SetWarnings False
        
            filename = f.selectedItems.Count
            'DoCmd.TransferText acImportDelim, , "YOURTABLENAME", filename, False
            MsgBox ("import" + filename + "?")
            
          DoCmd.TransferSpreadsheet acImport, , "Tabletest", filename, True
    
        DoCmd.SetWarnings True
        DoCmd.OpenQuery "matchedtest"
        'DoCmd.SetWarnings False
        'DoCmd.RunSQL "DELETE * FROM Tabletest"
        
        
    Dim SQL As String
    
    
    'checks for duplicates between the two tables
    
    SQL = "SELECT Books.* FROM Books LEFT OUTER JOIN matchedtest ON  matchedtest.[asset number] = Books.[asset number] WHERE Books.[asset  number] = IS NOT NULL"
    
    If DCount("*", "matchedtest.[asset number]", "Books.[asset number]") < 1 Then
    
    'msg box if it finds it
    
    MsgBox ("nothing to update")
    Exit Sub
    Else
    MsgBox ("updating")
    
    'string creation and insert
    
    
    SQL = "INSERT INTO Transactions([asset number])VALUES ('" & [Asset Number] & "')"
    
    End If
    
    
    CurrentDb.Execute SQL
    
    
    
    
    
    End Sub

    it's just saying it doesn't exist when I try to import it

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not understanding much of this code.

    Why multi-select for the FileDialog? You declare a path variable but don't see it getting set and used. You are setting the filename variable to a Count value, not a file name. The DCount expression doesn't make sense to me.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    token_remedie is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2011
    Posts
    13
    i cleaned it up, and got it working with this:

    Code:
    Private Sub Command0_Click()
        Dim fd As FileDialog
        Dim strfile As String
        Dim strsearchpath As String
        Dim vrtSelectedItem As Variant
        
     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", "*.xls", 1
         .Title = "locted of files"
         .InitialFileName = strsearchpath
         
    DoCmd.SetWarnings False
    
    If .Show = True Then
        For Each vrtSelectedItem In .SelectedItems
         MsgBox "file chosen = " & vrtSelectedItem
           ' pass the file information to another routine that handles the transfer
          DoCmd.TransferSpreadsheet acImport, , "Tabletest", vrtSelectedItem, True, "Master!"
        Next
        
        Else
        MsgBox "cancelled"
        
        End If
        End With
         
     
     End Sub
    I kind of need it to force the import now or include some sort of error handler to put up a msgbox for what's happening if it's broke.

    the next part is going to be cleaning up the imported data with sql...not looking forward to that part :S

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

Similar Threads

  1. Replies: 8
    Last Post: 02-03-2011, 09:51 AM
  2. updating an imported table
    By cmul in forum Access
    Replies: 3
    Last Post: 08-20-2010, 03:24 AM
  3. Linking Access Table with already imported External Data (Excel)
    By izzarshah in forum Import/Export Data
    Replies: 1
    Last Post: 07-29-2010, 09:40 AM
  4. Attachment data type INSERT INTO not working
    By LouisLouis in forum Programming
    Replies: 0
    Last Post: 09-27-2009, 02:23 PM
  5. Help with imported data
    By bubbasheeko in forum Queries
    Replies: 0
    Last Post: 01-12-2007, 07:12 AM

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