Results 1 to 4 of 4
  1. #1
    Ashfaque is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2021
    Posts
    31

    Vba code loop help require

    I have 2 sets of codes. One of them is for progress bar and another code set is for DSN less connection string that connects my all tbls from SQL Server into Access db. Both are working fine seprately.
    What I am looking for is to include progress bar codelines into other code so that the progress bar will get increased as per the tbl connects one-by-one and when it ends connecting (no more tbl remain to connect) till that time the barcode progress should reach to 100% and open the main form.
    I tried to adjust them but sometimes it is moving into indefinite loop and I have to restart the db. This is sure because both code set have LOOP so I believe one of then need to remove and adjust the code but It is confusing me. Please help..

    Code:
    'Code for Progress Bar
    
    Const DELAY As Single = 0.1 ' Progress Bar
    Dim intCnt As Integer
    Dim sngTimer As Single
    Dim cProg As New clsLblProgress
     
    With cProg
        .Initialize LblBack, LblFront, LblCaption
        .Max = 50
    End With
     
    For intCnt = 1 To 50
        sngTimer = Timer
            Do While Timer < sngTimer + DELAY
        DoEvents
        Loop
        cProg.Increment
    Next intCnt
    
    'Progress Bar Code Ends Here.
    
    'Code to connect server tbls
     
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim SqlStr As String
    Set db = CurrentDb
    Set rs = db.OpenRecordset("T_ServerTbls")
     
    rs.MoveLast
    rs.MoveFirst
     
    Do While Not rs.EOF
    If AttachDSNLessTable(rs!stLocalTableName, rs!stRemoteTableName, "(Local)", "HRINAT", "", "") Then
    End If
       rs.MoveNext             'press Ctrl+G to see debuG window beneath
    Loop
     
            DoCmd.OpenForm "F_MainBoard"


  2. #2
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    I am not be able to test it but, please, give a try to this:
    Code:
        Const DELAY As Single = 0.1
        Dim intCnt As Integer
        Dim sngTimer As Single
        Dim cProg As clsLblProgress
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim SqlStr As String
    
        Set db = CurrentDb
        Set rs = db.OpenRecordset("T_ServerTbls")
        
        'Check for returned records.
        If Not (rs.BOF And rs.EOF) Then
            'Get the actualy record count.
            rs.MoveLast
            rs.MoveFirst
            
            'Always, create an instance of an object
            'only if there is a reason to be.
            Set cProg = New clsLblProgress
            With cProg
                .Initialize LblBack, LblFront, LblCaption
                .Max = rs.RecordCount
            End With
    
            'Code to connect server tbls
            Do While Not rs.EOF
                'Delay...
                sngTimer = Timer
                Do While Timer < sngTimer + DELAY
                    DoEvents
                Loop
                'Connect the table.
                If AttachDSNLessTable(rs!stLocalTableName, rs!stRemoteTableName, "(Local)", "HRINAT", "", "") Then
                    cProg.Increment 'Only for connected tables. Otherwise, move this line under the next line.
                End If
                rs.MoveNext         'press Ctrl+G to see debuG window beneath
            Loop
            
            'Clean up.
            rs.Close
            'Release the instance of the clsLblProgress.
            Set cProg = Nothing
        End If
        'Release the recordset instance.
        Set rs = Nothing
        'Release the Database instance.
        Set db = Nothing
        'Open your main form.
        DoCmd.OpenForm "F_MainBoard"
    Let me know if it works properly.

    Regards,
    John

  3. #3
    Ashfaque is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2021
    Posts
    31
    Thanks a ton John,

    Extremely Super...... Brilliantly working....

  4. #4
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Happy to help!

    Good luck with your project,
    John

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

Similar Threads

  1. Do ... Loop Code error
    By Poohbear0471 in forum Programming
    Replies: 5
    Last Post: 06-11-2020, 12:31 PM
  2. Replies: 13
    Last Post: 12-27-2018, 05:56 PM
  3. Replies: 12
    Last Post: 06-05-2015, 04:27 PM
  4. Replies: 13
    Last Post: 08-20-2014, 09:17 AM
  5. VBA code to require user to enter a Value
    By rlsublime in forum Access
    Replies: 1
    Last Post: 03-14-2012, 04:34 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