Security for a cmd button

SASHA_D

Registered User.
Local time
Today, 14:39
Joined
May 12, 2003
Messages
48
Hi Everyone,

I have added user level security to my database-this all seems fine, however I need to stop particular users' from viewing a certain form. To view the form a user clicks a command button-this searches for records based on the current record displayed. If there are no matches, then a message is displayed "Sorry No data for this product", if there are matches then a form opens with the relevant records.
I have set the Access security so that the people in question cannot view the form, however when these people click the button they get the "Sorry No data for this product" message.
I need to be able to change this message so that if they are able to view it then it displays either the form with the records or the 'no data message', if they are not allowed to view it then display a message "Sorry not authorized!" or something.
I'm not sure how I do this-can anyone help?

Many Thanks!

Sasha.
 
SASHA_D said:
Hi Everyone,

I have added user level security to my database-this all seems fine, however I need to stop particular users' from viewing a certain form. To view the form a user clicks a command button-this searches for records based on the current record displayed. If there are no matches, then a message is displayed "Sorry No data for this product", if there are matches then a form opens with the relevant records.
I have set the Access security so that the people in question cannot view the form, however when these people click the button they get the "Sorry No data for this product" message.
I need to be able to change this message so that if they are able to view it then it displays either the form with the records or the 'no data message', if they are not allowed to view it then display a message "Sorry not authorized!" or something.
I'm not sure how I do this-can anyone help?

Many Thanks!

Sasha.

What ???

Code:
If (UserAllowedToLook(strUserName)) then
   DoCmd.OpenForm "frmYourForm"
else
   MsgBox "Sorry not authorized!"
end if

what's the dilly ?
 
Thanks for the reply,

Sorry I am a newbie to this stuff-how do I get the users' names?-I've used the Access built in security wizards.
Also, the code below is what I currently have behind the button and I am not sure how I would combine this with the if statement you supplied.

Many thanks,

Sasha

Private Sub Command23_Click()
On Error GoTo Err_Command23_Click
Dim stLinkCriteria As String
Dim stDocName As String
stDocName = "Cascade Form"
stLinkCriteria = ""
stLinkCriteria = stLinkCriteria & "[PIP] = " & " '" & Me![PIP] & "' And "
stLinkCriteria = Left(stLinkCriteria, Len(stLinkCriteria) - 4)
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command23_Click:
Exit Sub
Err_Command23_Click:
MsgBox ("No Cascade for this Product!")
Resume Exit_Command23_Click
End Sub
 
Sasha:

Below is code I use for a delete command button. It picks up the user group create in Access security to see if they are authorized to delete the record. It also does some other things. It looks to see if the record is blank first but you could make the button Visible=No until the record is selected first. It calls an Invisible routine so that the form is set to blank again after deletion. To check against a user name substitute UserNames for UserGroups maybe. I always work with groups which is much easier.

Code:
Private Sub btnDelete_Click()
On Error GoTo Err_btnDelete103_Click

    Dim stDocName As String
    Dim stLinkCriteria As String
    Dim varReturn As Variant
    
    If Not cboECNLookup.Value = "" Then
        If InStr(UserGroups(), "Admins") > 0 Then
            DoCmd.SetWarnings False
            varReturn = MsgBox("You are about to delete this ECN." & vbCrLf & _
            "Are you sure that this is what you want to do?", vbYesNo + vbDefaultButton2 + vbApplicationModal, "ECN Delete!")
            If varReturn = vbYes Then
            DoCmd.RunCommand acCmdDeleteRecord
            Me.cboECNLookup = ""
            Me.cboECNLookup.SetFocus
            Call Make_Invisible
            Else: Me.cboECNLookup = ""
                Me.cboECNLookup.SetFocus
            End If
        Else
            MsgBox ("You do not have the necessary permissions to delete an ECN." & vbCrLf & _
                "Please See System Administrator")
            Exit Sub
        End If
    Else: MsgBox "Please select an ECN Number from the drop down list on the left."
    End If

Exit_btnDelete_Click:
 

Users who are viewing this thread

Back
Top Bottom