CHECKBOX ON LISTVIEW DOESN’T MARK ALL CHECKS

Asked

Viewed 38 times

0

Good afternoon Personal,

I have the following structure:

Table: User

Codigo: 1
Login: João

Codigo: 2
Login: Maria

Table: User_permissions

Codigo: 1
Permissao: 'ESTORNAR'


Codigo: 2
Permissao: 'AJUSTE'

Table: Users and accesses

Cod_Usuario: 1
Cod_Permissao: 1


Cod_Usuario: 1
Cod_Permissao: 2


Cod_Usuario: 2
Cod_Permissao: 1

There are 3 tables... one with my users, others with the created permissions and another is the relationship of the 2 tables (that is, which permission each user has). In short: João can ESTORNAR and AJUSTE and Maria can only ESTORNAR.

I need to play all permissions on a listview with checkbox.... if the user has a permission check = true, otherwise check = false in the permission it has.

I did so:

sSQL = 'SELECT usuario.*, usuario_permissoes.*, Usuario_Acessos.*, usuario_permissoes.permissao ' & _
'FROM usuario INNER JOIN usuario_acessos ON usuario.codigo = Usuario_Acessos.cod_usuario INNER JOIN usuario_permissoes ON usuario_permissoes.codigo = Usuario_Acessos.cod_permissao ' & _
'WHERE (usuario_acessos.cod_usuario = ' & txtCodLogin.Text & ')'

Set r = dbData.OpenRecordset(sSQL)

If r.BOF Then
    If r.State <> 0 Then r.Close
    Set r = Nothing
    Exit Sub
End If

Check1.Value = 0

Call LerAcesso

Sub LerAcesso()
Dim i As Integer

For i = 1 To ListView1.ListItems.Count
    If ListView1.ListItems.Item(i).Text = 'ESTORNAR' Then
        ListView1.ListItems.Item(i).Checked = IIf(r.Fields('Cod_Permissao') = 1, True, False)
    ElseIf ListView1.ListItems.Item(i).Text = 'AJUSTE' Then
        ListView1.ListItems.Item(i).Checked = IIf(r.Fields('Cod_Permissao') = 2, True, False)
    ElseIf ListView1.ListItems.Item(i).Text = 'EXCLUIR' Then
        ListView1.ListItems.Item(i).Checked = IIf(r.Fields('Cod_Permissao') = 3, True, False)
    ElseIf ListView1.ListItems.Item(i).Text = 'REATIVAR' Then
        ListView1.ListItems.Item(i).Checked = IIf(r.Fields('Cod_Permissao') = 4, True, False)
    End If
Next
End Sub

The permissions appear in listview... it even marks(check=true) a permission, but if the user has 2 or more permissions, he does not check the others

What can I do to make it right?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.