Results 1 to 6 of 6
  1. #1
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568

    Every day uptading table as flat Excel file into Access

    Hi Guys,



    this is crossed post from here (there is no answer from days):

    https://www.access-programmers.co.uk...d.php?t=294220

    I would like to add here my sample database where I am linking Dictionary table from Excel (flat file which is automatically updated with QV every day) with Access Front-end.


    I created relationships with unique field (Zleceniodawca_nr) between Access table and Excel table like here in the picture:

    https://ibb.co/b6eLhk



    It is good approach to do that?
    Or better :
    1) make apend query and update query while access is starting and extract this data into Access table?
    2) Do not create relationships between tables and leave Excel file as alone stand by dictionary- table?


    Please help, maybe here someone will be known that
    Best wishes,
    Thank you in advance,
    Jacek Antek
    Attached Files Attached Files

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,981
    You did get an answer to the original PST at AWF on the same day you posted
    Use an append query then an update query

    You also said in the OP that the excel file didn't have an ID field.
    So import it to a temp 'buffer' table then append from that.
    Afterwards delete the temp table

  3. #3
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Thank you ridders52!

    Ok so it is better approach to transform it to Access format , and later add primary key into this table then use Excel file?
    And run this queries each time front - end is started?

    edit: I am asking about this because of knowledge. Knowledge of doing applications in Access in best possible way.

    Thank you,
    Jacek

  4. #4
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Ok i see the problem:

    where 2 users are trying to add something using Excel tables it is an error: file is only to read because another user is sitting there....

    So obviously I have to create these 2 queries in order to make Access possible to run smoothly...

    Best regards,
    Jacek

  5. #5
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    My solution to others:

    My code:

    Code:
    Public Sub Import()
    
    Dim sDBFile As String
    Dim sXLSFile As String
    Dim sSheet As String
    Dim sTableName As String
    
    
    DoCmd.SetWarnings False
        DoCmd.RunSQL "DELETE * FROM tbl_temp_dok"
    
    
    'On Error Resume Next
    '    DoCmd.SetWarnings False
    '    DoCmd.RunSQL "DROP TABLE tbl_slow_Dokumenty"
    '    DoCmd.SetWarnings True
    'On Error GoTo 0
    
    
    sDBFile = "C:\Users\ljar01\Desktop\Makro Braki Access\Nowy\Aplikacja_Braki_FE.accde"
    sXLSFile = "C:\Users\ljar01\Desktop\Makro Braki Access\Nowy\Słownik.xlsx"
    sSheet = "Dokumenty"
    sTableName = "tbl_temp_dok"
    '
    'CurrentDb.Execute "SELECT * INTO [;DATABASE=" & _
    'sDBFile & ";]." & sTableName & _
    '" FROM [Excel 8.0;HDR=Yes;DATABASE=" & _
    'sXLSFile & ";].[" & sSheet & "$];", dbFailOnError
    ''DoCmd.TransferDatabase acLink, "Microsoft Access", sDBFile, _
    acTable, sTableName, sTableName
    
    
    CurrentDb.Execute "INSERT INTO tbl_temp_dok SELECT * FROM [Excel 8.0;HDR=Yes;DATABASE=" & _
    sXLSFile & ";].[" & sSheet & "$];", dbFailOnError
    
    
    DoCmd.OpenQuery "QryUpdateDok"
    DoCmd.OpenQuery "QryAppendDok"
    DoCmd.OpenQuery "QryDeleteDok"
    
    
    DoCmd.SetWarnings True
    
    
    End Sub
    This code is running when user is opening front-end (Access Runtime):
    1) delete data from tbl_temp_dok (which is not linked table)
    2) Next step is to insert all data drom Excel to Access temp table
    3) run update and appned quries

    QryUpdateDok - first I am uptading existing fields:

    Code:
    UPDATE tbl_slow_Dokumenty INNER JOIN tbl_temp_dok ON tbl_slow_Dokumenty.Numer=[tbl_temp_dok].Numer 
    SET tbl_slow_Dokumenty.Obowiązkowy = [tbl_temp_dok].Obowiązkowy, tbl_slow_Dokumenty.Dokument = [tbl_temp_dok].Dokument;
    QryAppendDok - secondly I am appending non existing fields:
    Code:
    INSERT INTO tbl_slow_Dokumenty
    SELECT tbl_temp_dok.*
    FROM tbl_temp_dok LEFT JOIN tbl_slow_Dokumenty ON tbl_slow_Dokumenty.Numer=[tbl_temp_dok].Numer
    WHERE tbl_slow_Dokumenty.Numer Is Null;
    edit:

    I added also delete query to check if records in tbl_slow_Dokumenty were deleted from tbl_temp:

    Code:
    DELETE tbl_slow_Dokumenty.*FROM tbl_slow_Dokumenty
    WHERE tbl_slow_Dokumenty.Numer NOT IN (SELECT tbl_temp_dok.Numer FROM tbl_temp_dok);
    I do not know this is good approach to build databases using flat Excel files but referencing to Access Gurus answers - this is a good way.

    Best Wishes
    Jacek

  6. #6
    jaryszek is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2016
    Posts
    568
    Hello Guys,

    i would like to close the topic but I am wondering about one more thing.

    What if do you have for example 15 every day updating tables?
    For each of them I have to run update,append and delete query and run a code?

    Hmm maybe automatization in VBA only?

    What do you think Gurus?

    Best Wishes,
    Jacek

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

Similar Threads

  1. Replies: 5
    Last Post: 05-25-2016, 12:43 PM
  2. Export Access table data to flat file (txt file)
    By edmscan in forum Import/Export Data
    Replies: 3
    Last Post: 06-17-2015, 12:03 PM
  3. 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
  4. Flat File Query
    By mma3824 in forum Queries
    Replies: 1
    Last Post: 10-09-2012, 08:54 AM
  5. Creating a Flat File with Signed Numeric Data Fields
    By two_smooth in forum Database Design
    Replies: 2
    Last Post: 10-27-2010, 08:31 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