Results 1 to 2 of 2
  1. #1
    katjoe is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2024
    Posts
    14

    Update Query

    Hi,
    Looking for help with update query.
    A bit of background:

    I created a database with three tables that I have imported three tabs from an Excel spreadsheet.
    I got it to import the files and then move the file to another folder. All works well!



    Now, if one of the files that has already been imported was updated with new data I do not want to import the data instead I would like to update the record that matches the file name.

    Not sure which is the best way to go about this but I would like the file to either update the data in the table such as if …THEN data updated else import the data.
    I created a table which holds the file names and so I am not sure which is best to use.
    Option 1: create a “if/then” condition and if it meets the criteria then update the data or if not then import the data into the table.
    But not sure how to create this condition (WKS is an object). I did begin the condition with:
    #
    IF (WKS.name = “table1.file Name.values” = filename) THEN
    strSQL = “UPDATE [table1[ SET [ID] = “” WHERE [File Name] = ‘ ” & filename & “ ‘;” (filename is a variable that holds the name of the Excel file)
    #
    Access did not seem to like this.

    Option2:
    Create and update statement but the problem is that I do not know the ID for the particular row since there are about 300 records in the spreadsheet.
    I thought of using a select statement within the Update statement that I have listed below but I get a syntax error.
    #
    strSQL = “UPDATE [table1] SET (SELECT * FROM [table1] WHERE File Name = ‘ “ & filename & “ ‘) ;”
    #

    I have search for ideas but only get part answers. There is so many ways but not able to find anything close. Can someone please help?

    Many thanks in advance!!

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why are you posting this question YET AGAIN?
    https://www.accessforums.net/showthr...ghlight=upsert
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 9
    Last Post: 08-08-2023, 09:48 PM
  2. Replies: 4
    Last Post: 03-09-2022, 11:28 AM
  3. Replies: 2
    Last Post: 08-03-2017, 04:58 AM
  4. Replies: 1
    Last Post: 10-27-2016, 12:14 PM
  5. Replies: 7
    Last Post: 08-26-2013, 06:05 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