Results 1 to 4 of 4
  1. #1
    kvn5x4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    11

    Compare Access Table to Excel File

    I am wanting to create a macro that will compare the values of one column in a table in my Access database to values of one column in an excel file. These are two completely different files, but the columns in each file can have similar values (I.E. Catalog Number). However, the excel file has a dynamically changing file name. Additionally, values to this excel file are added/removed every day. So the program will need to take that into account as well. The name of the file changes according to the date (I.E. for today's file, it would be "Production 0611.xlsx". Similarly, tomorrow's file would be "Production 0612.xlsx". I am then wanting to send an email with the information of the catalog numbers that match in both files.

    On the macro side, I have an idea of how to open the dynamically changing excel sheet and how to email someone through Access. However, I am not sure how to compare both values of the tables and collect the information to send in the email (as it may change dynamically). To illustrate my concept better, here is something I made up.

    Click image for larger version. 

Name:	Untitled.jpg 
Views:	8 
Size:	25.0 KB 
ID:	16793



    All help is appreciated!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't think macro can handle this.

    Need VBA code that can create/modify links and query objects.

    As for the query, seems to be simple SELECT with INNER join.
    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
    kvn5x4 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    11
    June7, this is what I have so far. Could you please advise on the Inner Join query? I have never really understood the SQL stuff very well.

    Note: F14 is the same column for "CatalogNumber" in the excel file. When I link the excel file to the database, that's the name of the field it is given.

    Thanks!

    Code:
    Public Sub Match()
    Dim File_name As String
    Dim Path As String
    
    File_name = "IT_Production " & Format(Now(), "mm") & Format(Now(), "dd")
    Path = "S:\IT Production Meeting\IT_Production " & Format(Now(), "mm") & Format(Now(), "dd") & ".xlsx"
    
    'Links dynamically changing excel file name to Access
    DoCmd.TransferSpreadsheet acLink, , File_name, Path
    
    
    'Query
    "SELECT tblOverstock.CatalogNumber" & _
    From tblOverstock & _
    INNER JOIN File_Name _
    ON tblOverstock.CatalogNumber = File_name.F14

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The TransferSpreadsheet syntax looks good. But why are you using Now() for filename of the spreadsheet. Now() is the current date/time down to the second, so it is changing every second. Maybe you meant Date()?

    The query part code is not right. Here is code to build the sql statement:

    strSQL = "SELECT tblOverstock.CatalogNumber FROM tblOverstock INNER JOIN [" & File_Name & "] ON tblOverstock.CatalogNumber = [" & File_name & "].F14;"

    I am not sure what you want to do with query. Do you want to create a query object or maybe just set the RecordSource property of a form or report?

    If you want to create a query object that requires QueryDefs collection. Review: http://stackoverflow.com/questions/3...ccess-2003-vba
    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.

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

Similar Threads

  1. Need Help Sending an Excel File to Access Table via VBA
    By jamesdeuce in forum Programming
    Replies: 8
    Last Post: 10-05-2013, 06:08 PM
  2. Replies: 2
    Last Post: 08-05-2012, 06:32 PM
  3. Replies: 5
    Last Post: 02-24-2012, 11:02 AM
  4. Replies: 2
    Last Post: 02-11-2012, 07:52 PM
  5. Adapting Excel File to Access Table
    By mbake085 in forum Access
    Replies: 2
    Last Post: 05-18-2011, 10:41 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