Results 1 to 9 of 9
  1. #1
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77

    Link Tables with progress Bar

    currently i am using this code to ReLink Tables and flash the status bar so the user is aware there is activity BUT most do not see it and get impatient. So I have a form with a progress bar type solution. having some difficulty combining the two. there are 19 linked tables that i can pull the qty from using this code DCount("*", "MSysObjects", "Type = 4")



    Code:
    Public Function RelinkTables() '(environment As Integer)    On Error Resume Next
        Dim tblDef As DAO.TableDef
        Dim LinkedTableCount As Integer
        
        Form_frm_Progress.TimerInterval = 250
        
        LinkedTableCount = DCount("*", "MSysObjects", "Type = 4")
        
        For Each tblDef In CurrentDb.TableDefs
            If tblDef.Connect <> "" Then
                tblDef.Connect = DLookup("ODBCPath", "tbl_SystemInfo", "SystemInfoID= 1")
                'tblDef.Connect = GetConnectionString(environment)
                Status ("Linking Table......")
                tblDef.RefreshLink
                
            End If
                Status ("")
        Next
    
    
    End Function
    Code:
    Sub Status(pstrStatus As String)    
        Dim lvarStatus As Variant
      
        If pstrStatus = "" Then
            lvarStatus = SysCmd(acSysCmdClearStatus)
        Else
            lvarStatus = SysCmd(acSysCmdSetStatus, pstrStatus)
        End If
        
    End Sub
    here is the form i am using

    Code:
    Private Sub Command2_Click()Dim LinkedTableCount As Integer
    LinkedTableCount = DCount("*", "MSysObjects", "Type = 4")
    Me.TimerInterval = 250
    End Sub
    
    
    Private Sub Form_Timer()
    Me.txtCount = Me.txtCount + 1
    Me.Box3.Width = Me.txtCount * 100
    If Me.txtCount = 100 Then
    Me.TimerInterval = 0
    
    End If
    End Sub
    cant figure out how to combine them. after each table gets linked it updates the progress bar.

    Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Count the number of tables to link and update as each is done?
    So if 10 tables, as each is processed, then increase by 10% ?
    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

  3. #3
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    That’s the plan but need the code to do that. I think the code is close but not sure where to put what.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Have done exactly that and can tell you it's doable but not quite as simple. At least, not the way I did it.
    First, in between steps you need to repaint the form or much of the time the bar won't change due to screen update lag - the next task will begin before that can happen. To overcome that you need to also create a slight pause (e.g. a function call with a small timer counter). I never knew about Do Events in those days, so maybe I made it more difficult than it needed to be.

    Not sure what the issue really is - how to integrate both codes into one procedure? Can you post what you tried if you're not going to use the suggested method?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    This shows a screenshot of a form I use for relinking tables:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	23 
Size:	50.0 KB 
ID:	47549

    As you can see, I have a progress bar on the form itself as that is more obvious than the progress marker on the status bar
    If you like the idea, you can download the code from Progress Bar (isladogs.co.uk)

    There are 3 functions in modProgress: SetupProgressBar, UpdateProgressBar & HideProgressBar which you would need to import.
    You would use these in your RelinkTables procedure:

    Code:
    Public Function RelinkTables() '(environment As Integer)    On Error Resume Next
        Dim tblDef As DAO.TableDef
        Dim iCount As Integer
        
        Form_frm_Progress.TimerInterval = 250
        
        iCount = DCount("*", "MSysObjects", "Type = 4")
    
        SetupProgressBar 
     
            For Each tblDef In CurrentDb.TableDefs
            If tblDef.Connect <> "" Then
                tblDef.Connect = DLookup("ODBCPath", "tbl_SystemInfo", "SystemInfoID= 1")
                'tblDef.Connect = GetConnectionString(environment)
               '  Status ("Linking Table......")
                tblDef.RefreshLink
                UpdateProgressBar
                
            End If
              '   Status ("")
        Next
    
        HideProgressBar
    
    End Function
    OPTIONAL: You can also add a label showing the table currently being linked as in the screenshot above

    BTW If you have any linked Access or Excel tables etc, these have Type = 6
    Last edited by isladogs; 03-28-2022 at 01:15 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    Great Stuff Colin, Thank You

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You're welcome

    EDIT:
    The notification email included a question about adding the name of the table currently being linked to a form label.
    As that part isn't in your post any longer, I assume you've already worked out how to do that
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    jazzy is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Nov 2021
    Posts
    77
    got it working, problem is the progress completes and the tables are still linking. i had to move the iCount = DCount("*", "MSysObjects", "Type = 4") to the SetupProgressBar for the bar to display 1 of 19 tables. it also looks like the progress bar is incrementing by 2........ 2 of 19, 4 of 19 etc....

    any insight would be appreciated

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    If its increasing in steps of two, you must be duplicating the incremental count somehow.
    Try debugging step by step.

    Compare with my example app. That uses a timer but the basic idea is the same
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Replies: 4
    Last Post: 11-03-2020, 10:32 AM
  2. Check Link to DB tables and re-link
    By alberigo67 in forum Programming
    Replies: 2
    Last Post: 08-11-2020, 09:52 AM
  3. Replies: 5
    Last Post: 11-24-2017, 10:57 PM
  4. Replies: 2
    Last Post: 06-08-2017, 07:32 AM
  5. Trying to Link tables
    By brandonze in forum Access
    Replies: 1
    Last Post: 05-19-2011, 11:03 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