Ally
Registered User.
- Local time
- Today, 20:26
- Joined
- Sep 18, 2001
- Messages
- 617
I am completely useless when it comes to code. I've got some user code (given to me) where I want to give users with a certain LevelID either AllowEdit rights or not.
Rather than put the code in every single form, I'd like to call the function but am getting an error.
My function is:
I have Run fAllowEdits OnLoad of a form.
I get the error message:
"...can't find the form frmName referred to in a macro expression or visual basic code..." with the blue bit above highlighted as the problem bit.
Is it possible to do what I'm trying to do please? Hope I've explained it ok.
Rather than put the code in every single form, I'd like to call the function but am getting an error.
My function is:
Code:
Public Function fAllowEdits()
Dim ctl As Control, frm As Form, Db As Database, r As Recordset
Dim Lev As Integer, intCanEdit As Integer, Nme As String, frmName As String
[color=blue]Set frm = Forms!frmName[/color]
Set Db = CurrentDb
Set r = Db.OpenRecordset("tblUsers")
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
msgbox "Current form is " & frmCurrentForm.Name
Call fOSUserName2
Nme = fOSUserName2
Do While Not r.EOF
If Nme = r.Fields("Username") Then
Lev = r.Fields("LevelID")
End If
r.MoveNext
Loop
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acTextBox
If Lev = 2 Then
intCanEdit = False
Else
intCanEdit = True
End If
End Select
End With
Next ctl
If intCanEdit = False Then
With frm
.AllowAdditions = False
.AllowDeletions = False
.AllowEdits = False
End With
Else
With frm
.AllowAdditions = True
.AllowDeletions = True
.AllowEdits = True
End With
End If
End Function
I have Run fAllowEdits OnLoad of a form.
I get the error message:
"...can't find the form frmName referred to in a macro expression or visual basic code..." with the blue bit above highlighted as the problem bit.
Is it possible to do what I'm trying to do please? Hope I've explained it ok.