Results 1 to 2 of 2
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,046

    VBA function to UPDATE date value for all tables where tables have same prefix

    Hello:

    I need some assistance with correcting an UPDATE function (i.e., VBA) which will update a date field with a specified date value.

    Background:
    - Attached DB contains six (6) tables.
    - Out of those 6 tables, 5 tables have a prefix = "LK_"
    - Each "LK_" table has different fields; however, each table includes date field [DATE_UPDATED].
    - Table "Data_Dictionary" should NOT be updated as part of the VBA UPDATE routine. That is, the VBA routine must only update all tables where first 3 characters = "LK_".

    Proposed Code:

    Code:
    Private Sub cmdUpdateDate_Click()
    
        Dim tdf As DAO.TableDef
      
            For Each tdf In db.TableDefs
                If Left(tdf.Name, 4) <> "Msys" _
                    And Left(tdf.Name, 3) = "LK_" Then
        
                    CurrentDb.Execute "UPDATE " & tdf.Name & " SET " & tdf.Name & ".DATE_UPDATED = '07/30/2021';"
                    
                End If
            Next tdf
    
    End Sub
    As of now, I'm getting run-time error "424 - Object Required". What am I missing? How does the VBA need to be corrected update all LK table's field [DATE_UPDATED]?



    Thank you,
    Tom
    Attached Files Attached Files

  2. #2
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,046
    Never mind... the following mods fixed the issue:

    Code:
    Private Sub cmdUpdateDate_Click()
    
    
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim tdf As DAO.TableDef
      
        Set db = CurrentDb()
      
            For Each tdf In db.TableDefs
                If Left(tdf.Name, 4) <> "Msys" _
                    And Left(tdf.Name, 3) = "LK_" Then
    
    
                    CurrentDb.Execute "UPDATE " & tdf.Name & " SET " & tdf.Name & ".DATE_UPDATED = '07/30/2021';"
                    
                End If
            Next tdf
    
    
    End Sub

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

Similar Threads

  1. VBA ForLoop to rename all tables with same *prefix*
    By skydivetom in forum Programming
    Replies: 7
    Last Post: 04-02-2021, 09:26 AM
  2. Replies: 6
    Last Post: 11-05-2014, 05:27 PM
  3. Replies: 2
    Last Post: 07-15-2014, 10:39 AM
  4. Replies: 6
    Last Post: 05-31-2013, 07:46 PM
  5. Replies: 10
    Last Post: 07-12-2011, 11:09 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