need help with this function call - please

NPUser

Registered User.
Local time
Today, 03:04
Joined
Jul 25, 2004
Messages
55
I am trying call below function with either of these call routine, but without sucess. Instead of variable FrmName if i use hard coded form name then everything works like it supposed to. I would like to call this funcation from custom toolbar or also from other forms as well. Any thought?



'Check Permission Function Call

Check_Permission Forms!form1

or

Check_Permission (Forms!form1)


Function Check_Permission(FrmName as Form)
'Quick Function Test - remove later
'If Forms!Form1!t55.Value = "6666" Then

'Actual usage
If CurrentUser = "Viewer" Then
Beep
MsgBox "You do not have permission to this item.", vbCritical, "Access Denied"
Exit Function
Else

DoCmd.OpenForm FrmName, acNormal, "", "", , acNormal
DoCmd.GoToRecord acForm, FrmName, acLast
End If
End Function
 
You have to pass it a FORM OBJECT (your parameter). If you pass a text form name, then it is not a form object. If you hard code a form name, access passes the form object instead.
I think
 
Sorry if i misunderstood you. So if i do this i should work. Is that what you are saying?


Function Check_Permission(FrmName as Form)
Dim x as Object
x = FrmName

If CurrentUser = "Viewer" Then
Beep
MsgBox "You do not have permission to this item.", vbCritical, "Access Denied"
Exit Function
Else

DoCmd.OpenForm x, acNormal, "", "", , acNormal
DoCmd.GoToRecord acForm, x, acLast
End If
End Function
 
Dim FrmName as string
FrmName = Forms!Form1
Check_Permission(FrmName)
Would not work (you are passing a text (string) instead of a form.

Check_Permission(Forms!Form1)
should work as you are passing the actual form.

Question, what is CurrentUser?
Why do you have to pass a form?
 
FoFa said:
Check_Permission(Forms!Form1)
should work as you are passing the actual form.
It did not work as i mention in my orginal posting. I tried:

Check_Permission Forms!form1
or
Check_Permission (Forms!form1)
or
Check_Permission (Forms![form1]) ' Just in case of if you have the spaces in form name



FoFa said:
Question, what is CurrentUser?

CurrentUser is a builtin function to get currently logged on user name. Viewer is a user.I could use ' if environ("Username") = "Viewer" then ' anyway that not the problem.

FoFa said:
Why do you have to pass a form?

So that i can deny access to certain forms for this user or any other user for that matter - just my calling this funcation with form as parameter.
 
Last edited:
OK, but why pass the whole form, why not just pass the value you are checking for instead?
Check_Permission(Forms!Form1!t55.Value)

Function Check_Permission(CheckValue as string)
If CheckValue = "6666" AND CurrentUser = "Viewer" Then
MsgBox "Sorry Charlie, You're Out-a-here"
DoCmd.CrashAccess vUnrecoverableError, vCorruptDBalso
End If
End Function
 
Thanks for the reply FOFA, i thought about that but it does not work for me because i need to open form after the security check in ELSE part. And i want to use the function multiple times for multiple forms, do not want to create a function for the each form.

Any thought?

sa
 
Last edited:
It is becoming more clear now.
You want to pass the form name so you can open the form. That would be a strinig value (not a form object).
Now, where is this value "6666" coming from?
 
I added bound text value to quickly check the function. I will remove it once i get the function working. Do not worry about "6666". As you can see actual usage of the form would be:

If CurrentUser = "Viewer" Then
'access denied message
else
'open form with form name parameter
end if

thanks
sa



Code:
Function Check_Permission(FrmName as Form)
'Quick Function Test - remove later
'If Forms!Form1!t55.Value = "6666" Then

'Actual usage
If CurrentUser = "Viewer" Then
Beep
MsgBox "You do not have permission to this item.", vbCritical, "Access Denied"
Exit Function
Else

DoCmd.OpenForm FrmName, acNormal, "", "", , acNormal
DoCmd.GoToRecord acForm, FrmName, acLast
End If
End Function
 
This works:

OpenAForm ("FormName")


Code:
Public Function OpenAForm(FormToOpen As String)
  DoCmd.OpenForm (FormToOpen)
End Function

You can add the appropriate test.
 
Thank you SIR!!. I think i tried that. Let me give it a go again.
sa
 

Users who are viewing this thread

Back
Top Bottom