- Local time
- Today, 12:07
- Joined
- Feb 28, 2001
- Messages
- 30,148
You would have to check the OpenArgs BEFORE that function IF the argument potentially would affect the outcome of that test.
@Gasman is offline currently so here goes - The quotes are there to add a single quote around each end of your string.Thank you. I'm confused by the multiple quotes. Why a single, double on the left and a double, single, double on the right?
Thank you. I'm confused by the multiple quotes. Why a single, double on the left and a double, single, double on the right?
Would I run the OpenArgs before or after that function?
If Globals.UserAccess(Me.Name) = False Then
MsgBox "You do not have the required permissions to access this feature.", vbOKOnly, "Access Denied"
DoCmd.CancelEvent
Cancel = True
elseif Me.OpenArgs<>""
Me.RecordSource = "select * from tblContracts Where ContractNo='" & Me.OpenArgs & "'"
End If
something like
Code:If Globals.UserAccess(Me.Name) = False Then MsgBox "You do not have the required permissions to access this feature.", vbOKOnly, "Access Denied" DoCmd.CancelEvent Cancel = True elseif Me.OpenArgs<>"" Me.RecordSource = "select * from tblContracts Where ContractNo='" & Me.OpenArgs & "'" End If
This function tests to see what the user access and type are in whichever form is (attempted) being opened.What are you expecting --- Globals.UserAccess(Me.Name) ---- to return?
Put a stop on that line of code. Then print it in the immediate window to see what you are getting.
Public Function UserAccess(FormName As String) As Boolean
UserAccess = Nz(DLookup("HasAccess", "tblUserAccess", "UserAccess_ID=" & TempVars("UserType") & " AND FormName='" & FormName & "'"), False)
End Function
Is this a function you wrote? Are you sure this is not where your security error is occuring?This function tests to see what the user access and type are in whichever form is (attempted) being opened.
Yes, well edited from one on a tutorial found online. It works on all my other open forms: They all deny access when appropriate.Is this a function you wrote? Are you sure this is not where your security error is occuring?
DoCmd.OpenForm "frmUpdateStatus", acNormal, "", "", acFormEdit, acDialog, Me.txtContractNo
I did...previously, it was ",,,,," etc. I only added them in this instance to see if that helped the error.No idea what 2501 is, but if you do not use the arguments and they are optional, just leave them out.
Code:Acnormal,,acformedit
On my phone so typing as little as needed,![]()
Still perplexed as to why the VB code would result in the issue when the macro does not; however, I added an On Error Resume Next and that took care of it in the "Denied Access" scenario, and it functions properly when logged in as a user with access as well.This is only happening on this button. And what is different for this one is that it uses VB to open the form, while the others use (no rotten tomatoes please) the macro Open Form.
I verified this by changing one that was previously the macro below, and changed it to the DoCmd.OpenForm and it now pops up the macro error following clicking the OK button on the "Access Denied" message. But none of the Open Form macro buttons encounter this issue. I'm at a loss as to why it would happen in the VB coding because the On open event handles what happens when the open form action is canceled (the "Access Denied" pop up). And the VB version is performing the same action as the macro below.
OK, a macro error (2501) pops up.
I will add the comment that this is the wrong time to cancel errors. You need to find the reason for the denial, correct that, and leave errors enabled. Otherwise you will have a potential multitude of errors that will not be reported. You only turn off errors in very rare situations.I added an On Error Resume Next and that took care of it