Password prompt help!!!!!!

Johnhook

New member
Local time
Today, 00:41
Joined
Sep 27, 2002
Messages
8
hi im making a database for a lorry company for my school ICT prject.

On my form i have a delete item button. The person I am designing it for has requested that only he can delete records.

I havent a clue about VBA but on a previous post for a similar problem somone gave me the perfect VB code for my problem.

Does anyone know the VB code that would upon click on the button make a pop up box requeting the password required to delete a record.

Thanks very much Jon Hook
 
Try this...
Code:
Private Sub bDeleteRecord_Click()
On Error GoTo Err_bDeleteRecord_Click
    
    Dim strInput As String
    Dim strMsg As String
    
    Beep
    strMsg = "Please key the Delete Password to allow the deletion of the current record."
    strInput = InputBox(Prompt:=strMsg, Title:="Delete Password")
    If strInput = "DeletePassword" Then
        Beep
        DoCmd.RunCommand acCmdDeleteRecord
        Refresh
    Else
        Beep
        MsgBox "Incorrect Password!" & Chr(13) & Chr(13) & "You are not allowed to delete any table records." & Chr(13) & Chr(13) & "Please contact your database administrator for help.", vbCritical, "Invalid Password"
        Exit Sub
    End If
    
Exit_bDeleteRecord_Click:
    Exit Sub
    
Err_bDeleteRecord_Click:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_bDeleteRecord_Click
    
End Sub
'You can not format an input box!

'HTH
 
The password is good if the db is unsecured but if you have security I would instead look at the current user to see if they are allowed to delete a record.

To look at the security workgroups to see if user is approved to delete a record create a delete password command button and into the on click event paste below. Replace text "YourCommandButton" with the name of your command button. Replace text "GroupWithDeleteRights" with the name of the appropriate security group.


Private Sub YourCommandButton_Click()
On Error GoTo Err_YourCommandButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

If InStr(UserGroups(), "GroupWithDeleteRights") > 0 Then
DoCmd.RunCommand acCmdDeleteRecord
Refresh
Else
MsgBox ("You do not have the necessary permissions to delete a record." & vbCrLf & _
"Please See System Administrator")
Exit Sub

End If

Exit_YourCommandButton_Click:
Exit Sub

Err_YourCommandButton_Click:
MsgBox Err.Description
Resume Exit_YourCommandButton_Click

End Sub

Autoeng
 

Users who are viewing this thread

Back
Top Bottom