Home > Software engineering >  How to use VBA to set different user operation privileges
How to use VBA to set different user operation privileges

Time:10-09

Login I did an inventory management system, which made a user rights management operation (see the appendix of furniture list for detail), the original user name, password, operation permissions are in Excel worksheets, normal operation, now I save it to the database user name password information data in the table, how do I write the code, we are enclosing the original code, ask everybody to help!!!!!! The attachment address: http://download.csdn.net/detail/longzhu0623/7204547
Personally think I demand write code is divided into three steps:
Step 1: link to the database and refreshes the list of users;
Step 2: list of user permissions to users for assignment;
Step 3: save the permissions to modify;
Now I finished step 1 and step 3 should be no problem, the key is to step 2, now I don't know how to write, please give directions, please!
Specific code is as follows (see the appendix of furniture list for detail) :
Dim CNN As New ADODB. Connection
Dim the RSX As ADODB. You
'step 1 code:
Private Sub UserForm_initialize ()
Dim I As an Integer, n As Long
Dim rsSQL As New ADODB. You
Dim As SQL String
Establishment and database connection
'With CNN
. The ConnectionString="Provider=Microsoft. Jet. The oledb. 4.0;" _
& "Data Source=" & amp; ThisWorkbook. Path & amp; "\ database. MDB;"
. Open
End With
SQL="select distinct user name from the user name password information for the order by the user name"
Set the RSX=New ADODB. You
The RSX. The Open SQL, CNN, adOpenKeyset, adLockOptimistic
With user list
. The Clear
EOF
the Do While Not RSX.The AddItem RSX! The user name
The RSX. MoveNext
Loop
End With
On the Error Resume Next
The user list. ListIndex=0
Application. EnableEvents=True
End Sub

Private Sub closed _Click ()
Unload Me
End Sub

'the original step 1 code:
'Private Sub UserForm_initialize ()
'Dim intRowsCount As an Integer, I, As an Integer
'Application. EnableEvents=False
'intRowsCount=user management. Range (" A "& amp; Rows. Count). End (xlUp). Row
'For I=2 To intRowsCount
'the user list. AddItem user management. Range (" A "& amp; I)
'Next
'the user list. ListIndex=0
'Application. EnableEvents=True
'End Sub
'
'Private Sub closed _Click ()
'the Unload Me
'End Sub

'the original code in step 3:
Private Sub determine _Click ()
Dim intRowsCount As an Integer, I, As an Integer
IntRowsCount=user management. Range (" A "& amp; Rows. Count). End (xlUp). Row
For I=2 To intRowsCount
If the user list. The Text=user management. Range (" A "& amp; I) Then
With user management
The Range (" C "& amp; I)=manage users. The Value
The Range (" D "& amp; I)=admin log. The Value
End With
End the If
Next I
Unload Me
End Sub

'the original code in step 2:
Private Sub user list _change ()
Dim intRowsCount As an Integer, I, As an Integer
IntRowsCount=user management. Range (" A "& amp; Rows. Count). End (xlUp). Row
For I=2 To intRowsCount
If the user management. Range (" A "& amp; I)=user list. The Text Then
With user management
Manage users. (Value=https://bbs.csdn.net/topics/CBool. Range (" C "& amp; I))
Admin log. (Value=https://bbs.csdn.net/topics/CBool. Range (" D "& amp; I))
End With
The Exit Sub
End the If
Manage users. Value=https://bbs.csdn.net/topics/False
Admin log. Value=https://bbs.csdn.net/topics/False
Next
End Sub
  •  Tags:  
  • VBA
  • Related