Ok here's what i want to do.

I woul like to disable the toolbar and menubar in my main form
depending on the usertype that was logged in.

My dbase field is UserType and record type can only be
User and Admin (Depends on the registration).

When a user log in which is a "User" type, toolbar and menubar is disabled.
If it is an admin type, they are enabled.

Oh, the user type is also displayed on my statusbar ("panel(2)").

Code for Main (form_load)

Private Sub Form_Load()

If StatusBar.Panels(2).Text = User Then
    Toolbar1.Enabled = False
Else
    Toolbar1.Enabled = True
End If

End Sub

For the login form:

Private Sub cmdLogin_Click()

Dim User As String
Dim CurrentPosition As String

passattemp = passattemp + 1
    
If txtUser.Text = "" And txtPass.Text = "" Then
    
    
    MsgBox "Data required, please enter a valid username and password!", vbInformation, "Log-in Error"
            
            txtUser.Text = ""
            txtPass.Text = ""
            txtUser.SetFocus
 Else
    
 
    Set db = New ADODB.Connection
        db.CursorLocation = adUseClient
        db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\Database.mdb"
    
    Set rs = New ADODB.Recordset
        rs.Open "select * from Users where UserName = '" & txtUser & "'", db, adOpenStatic, adLockOptimistic

            
                    
If Not rs.EOF Then
        

    If txtPass.Text = rs!Password Then
    MsgBox "Welcome to The Provincial Capitol Payroll System!", vbInformation, "Log-in Form"
    
    
                    User = cWords(txtUser.Text)
                    CurrentPosition = rs.Fields("UserType")
                                                
                    With Form2
                            .StatusBar.Panels(2).Text = User
                              
                        End With
                        Unload Me
                        Form2.Show
    
        Else
              MsgBox "Password Incorrect. Please enter a valid password!" & vbCrLf & " Attempt left " & 3 - passattemp & "", vbExclamation, "Log-in Form"
              txtPass.Text = ""
              txtPass.SetFocus
              
    
    Set rs = Nothing
                
            

End If
            
    Else
        MsgBox "This user does not exist. Access denied!" & vbCrLf & " Attempt left " & 3 - passattemp & "", vbExclamation, "Log In Error"
                txtUser.Text = ""
                txtPass.Text = ""
                txtUser.SetFocus
                
        End If
        
           
            If passattemp = 3 Then
                MsgBox "You are not an authorized user. Program will now Terminate", vbCritical, "Log In Error"
                End
            End If
       
    
End If

End Sub

I suppose the only reason you want to disable/enable the toolbar is because there is command buttons contained within it?

To do that, disable the actual buttons. The toolbar itself can not be disabled. You can however set it to visible true/false.

'Disable buttons...
Toolbar1.Buttons("MyButtonName").Enabled = True

I found this to work as well:

toolbar1.Buttons.Item(1).Enabled = False

and you are able to change the 'pressed' value with this:

toolbar1.Buttons.Item(1).Value = tbrUnpressed   'or tbrPressed'

Thanks for that sir.

Uhm i can hardly explain this one.

I only want to disable the toolbar and menubar

if a user account is used to log in.

And if admin account, all is enabled.

Lets say, in my Dbase, i have 3 fields,

Usertype, Username and Password.

Under Username, i have 'sample' as a username to login and its Usertype is 'User'.

How do i apply the disabling code if a user type account is used.

How will i do that (with Dbase connection)

Same for the Admin type.

On line 39 - 43

With Form2
.StatusBar.Panels(2).Text = User

End With
Unload Me

use an if then statement -

If User = "Admin" Then
   'nothing here if you want...
      Else
   toolbar1.Buttons.Item(1).Enabled = False
End if

I finally got it.

User = cWords(txtUser.Text)
                    CurrentPosition = rs.Fields("UserType")
                                                
                    With Form2
                    
                    .StatusBar.Panels(2).Text = User
                    
                        If rs.Fields("UserType").Value = "Admin" Then
                            
                            .Toolbar1.Enabled = True
                        
                        Else
                            
                            .Toolbar1.Enabled = False
                            
                            .mnuNewEmp.Enabled = False
                            .mnuCpayroll.Enabled = False
                            .mnuEmpinfo.Enabled = False
                            .mnuEmpdtr.Enabled = False
                            .mnuPayslip.Enabled = False
                            .mnuBackup.Enabled = False
                            .mnuRestore.Enabled = False
                            .mnuUreg.Enabled = False
     
                        End If
                              
                        
                            End With
                        Unload Me
                        Form2.Show

Thanks again sir.

//SOLVED

commented: Well done! +4

Well done. Some rep points for not giving up.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.