|
借用前辈编写的VB,显示为 .RecordCount 类型不匹配,大神们帮助看看是那里有问题 !谢谢!
Option Compare Database
Option Explicit
'用户登录的“用户编号”
Public UserID As String
'用户登录的“用户名”
Public UserName As String
Public varTemp(5) As Variant
Function OpenForm(FormID As Integer)
On Error GoTo Err_OpenForm
Dim I As Integer
Dim STemp As String
Dim Rs1 As ADODB.Recordset
Dim Rs2 As ADODB.Recordset
Set Rs1 = New ADODB.Recordset
Set Rs2 = New ADODB.Recordset
'打开“系统权限”数据表
STemp = "Select * From 系统权限"
Rs1.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'打开“系统窗体”数据表
STemp = "Select * From 系统窗体"
Rs2.Open STemp, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Dim blnOpen As Boolean
Dim FormName As String
blnOpen = False
'判断“系统权限”数据是否为空
If Rs1.RecordCount < 1 Then
blnOpen = False
Else
Rs1.MoveFirst
'判断当前“登录用户”是否有权限打开FormID对应的窗体
For I = 1 To Rs1.RecordCount
If Rs1("用户编号") = UserID And Rs1("窗体编号") = FormID _
And Rs1("权限") = True Then
blnOpen = True
Else
Rs1.MoveNext
End If
Next I
End If
'在“系统窗体”数据表中搜索待打开窗体的“名称”
Rs2.MoveFirst
For I = 1 To Rs2.RecordCount
If Rs2("窗体编号") = FormID Then
FormName = Rs2("窗体名称")
Else
Rs2.MoveNext
End If
Next I
'判断用户是否有权限打开窗体,blnOpen为“真”有权限
If blnOpen = False Then
MsgBox "您没有权限使用" & "“" & FormName & "”窗体", vbCritical, "无权使用"
Else
DoCmd.OpenForm FormName, acNormal, , , , acWindowNormal
End If
Set Rs1 = Nothing
Set Rs2 = Nothing
Exit Function
Err_OpenForm:
Set Rs1 = Nothing
Set Rs2 = Nothing
MsgBox Err.Description, vbOKOnly, "窗体打开错误"
End Function
|
|