I have a database I am creating with about 50 users over a network. There are about 6 groups of users and these users are spread across 10 branches. I want to block/allow users from particular forms and views. For example I want branch users forms to be filtered by their branch number but depending on the group they are in they can only see some forms. i.e. 50 users, 10 branches, each branch has about 5 ppl of where 1 is in group A and 4 are in group B. I want all users that belong to branch 1 to see the information they enter, but Group B enter data but cannot approved or delete, and group A can enter, approve and delete. So then. On my login form I have the user type his/her username but the i want LEAVE function to update 2 textbox where I have named GroupName and BranchNo. Basically to run a query and look for the username and return in one textbox that user's groupname and the other textbox the user's branch no. This information will be used to filter forms and block the user from certain controls. This is the code I have so far but still can't figure how to display the results.

Private Sub UsernameTextBox_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles UsernameTextBox.Leave
        'Make Connection to database
        Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Atlanet\loantracking\CTS_be.mdb")
        'Query information for Branch Number
        Dim BranchNumber As OleDbCommand = New OleDbCommand("SELECT Branch_Number From MSysUserList WHERE Username like '" & UsernameTextBox.Text & "'")
        BranchNo.Text = BranchNumber
        'Query information for User Group
        Dim UserGroup As OleDbCommand = New OleDbCommand("SELECT UserGroup From MSysUserList WHERE Username like '" & UsernameTextBox.Text & "'")
        UserGroupTextBox.Text = UserGroup
    End Sub

It keeps highlighting the BranchNumber and UserGroup and giving error "Value of type 'String' cannot be converted to System.Data.OledbCommand

What am I doing wrong?

Getting error because You are trying to assign the command into control text. Try below set of statements and Red color are modified

'Make Connection to database        
            Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Atlanet\loantracking\CTS_be.mdb")        
            'Query information for Branch Number        
            Dim BranchNumber As OleDbCommand = New OleDbCommand("SELECT Branch_Number From MSysUserList WHERE Username like '" & UsernameTextBox.Text & "'" ,con)        
            
            BranchNo.Text = BranchNumber.ExecuteScalar().ToString()        
            'Query information for User Group        
            Dim UserGroup As OleDbCommand = New OleDbCommand("SELECT UserGroup From MSysUserList WHERE Username like '" & UsernameTextBox.Text & "'" ,con)        
            UserGroupTextBox.Text = UserGroup.ExecuteScalar().ToString()

Getting error because You are trying to assign the command into control text. Try below set of statements and Red color are modified

'Make Connection to database        
            Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Atlanet\loantracking\CTS_be.mdb")        
 con.Open()           
'Query information for Branch Number        
            Dim BranchNumber As OleDbCommand = New OleDbCommand("SELECT Branch_Number From MSysUserList WHERE Username like '" & UsernameTextBox.Text & "'" ,con)        
            
            BranchNo.Text = BranchNumber.ExecuteScalar().ToString()        
            'Query information for User Group        
            Dim UserGroup As OleDbCommand = New OleDbCommand("SELECT UserGroup From MSysUserList WHERE Username like '" & UsernameTextBox.Text & "'" ,con)        
            UserGroupTextBox.Text = UserGroup.ExecuteScalar().ToString()

This worked but only after I added code to open the connection. See in GREEN.

Thanks so much for your help.

Edited 6 Years Ago by kayjenx: n/a

This question has already been answered. Start a new discussion instead.