Open menu - looping until closed (1 Viewer)

DKoehne

Registered User.
Local time
Today, 06:37
Joined
Apr 10, 2017
Messages
49
Hello. I have a main menu that has these three things on it: 1) a tunnel status, 2) an ADO state connection and 3) a set of buttons tied to role with case statement based on temp vars. The code I have is hanging up (not responding) - I believe I am close but it still needs some refining. If adStateOpen or PLINK_PID is dropped a reconnect for either is available and will need to return to the loop. The main menu remains open for the entire session (minimized) until needed or a logout occurs.

Any help would be appreciated. Thanks!

Code:
Private Sub Form_Current()
Dim PLINK_PID As Variant 'variant includes both null and integer
'set all icons to false upon entry
Me.connected.Visible = False
Me.secured.Visible = False
Me.unconnected.Visible = False
Me.unsecured.Visible = False
Do While Not Me.Logout.ControlType = True
    Do While adStateOpen = 1
        Do While TempVars("PLINK_PID") <> Null 'this is the inner loop while we have a valid plink pid number
            'Debug.Print "We have a valid connection and tunnel pid so test for role access"
                    If (TempVars("PLINK_PID") > 0 And (adStateOpen = 1) = True) Then
                        'show both icons as locked with blue
                        Me.connected.Visible = True
                        Me.secured.Visible = True
                        'set ones not needed to false
                        Me.unconnected.Visible = False
                        Me.unsecured.Visible = False
                        End If
                    If (TempVars("PLINK_PID") = Null And (adStateOpen = 1) = False) Then
                        'show both icons as locked with blue
                        Me.connected.Visible = False
                        Me.secured.Visible = False
                        'set ones not needed to false
                        Me.unconnected.Visible = True
                        Me.unsecured.Visible = True
                        MsgBox ("Both the secure connection and the database connections have been lost! Please Reconnect to both.")
                        End If
                    If (TempVars("PLINK_PID") > 0 And (adStateOpen = 1) = False) Then
                        'show both icons as locked with blue
                        Me.connected.Visible = False
                        Me.secured.Visible = True
                        'set ones not needed to false
                        Me.unconnected.Visible = True
                        Me.unsecured.Visible = False
                        MsgBox ("The database connection has been lost! Please reconnect to the database.")
                        End If
                    If (TempVars("PLINK_PID") = Null And (adStateOpen = 1) = True) Then
                        'show both icons as locked with blue
                        Me.connected.Visible = True
                        Me.secured.Visible = False
                        'set ones not needed to false
                        Me.unconnected.Visible = False
                        Me.unsecured.Visible = True
                        MsgBox ("The secure connection has been lost! Please reconnect securely.")
                        End If
                Loop
                
                
        
                Debug.Print "middle loop begins"  'this begins the outer loop
                Debug.Print TempVars("EmployeeType")
                Debug.Print adStateOpen

                    Select Case TempVars("EmployeeType")
                    'Buttons for CustomerService
                    
                    Case 20
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                                        
                    'Buttons for Negotiations
                    Case 30
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                                        
                    'Buttons for Legal
                    Case 40
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                    
                    'Buttons for Accounting
                    Case 50
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                                        
                    'Buttons for HR
                    Case 60
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                                        
                    'Buttons for Management
                    Case 70
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                                        
                    'Buttons for InformationTechnology
                    Case 80
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = True
                        Me.HR.Enabled = True
                        Me.InformationTechnology.Enabled = True
                        Me.Negotiations.Enabled = True
                        Me.Accounting.Enabled = True
                        Me.Management.Enabled = True
                        Me.Marketing.Enabled = True
                                        
                    'Buttons for Marketing
                    Case 90
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = False
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = False
                        Me.Marketing.Enabled = False
                                        
                    'Buttons for CSandNEGSupervisor
                    Case 21 Or 22
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = False
                        Me.HR.Enabled = False
                        Me.InformationTechnology.Enabled = False
                        Me.Negotiations.Enabled = True
                        Me.Accounting.Enabled = False
                        Me.Management.Enabled = True
                        Me.Marketing.Enabled = False
                    
                    
                    'Buttons for Manager
                    Case 70
                        Me.CustomerService.Enabled = True
                        Me.Legal.Enabled = True
                        Me.HR.Enabled = True
                        Me.InformationTechnology.Enabled = True
                        Me.Negotiations.Enabled = True
                        Me.Accounting.Enabled = True
                        Me.Management.Enabled = True
                        Me.Marketing.Enabled = True
                    
                    Case Else
                        MsgBox ("Something has gone wrong, please see a supervisor")
                    End Select
                    
            Loop
            
            Debug.Print "farthest outer loop begins"
            Me.Refresh 'refresh form to make current to continue loop
        Loop
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:37
Joined
Oct 29, 2018
Messages
21,357
Hi. Did you try stepping through it? Just curious...
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:37
Joined
Aug 30, 2003
Messages
36,118
I haven't used TempVars yet (old dog, new trick) but typically you can't use = or <> to test for Null. You might try using the IsNull() function and Not as appropriate:

If IsNull(Blah) Then

If Not IsNull(Blah) Then
 

Users who are viewing this thread

Top Bottom