Password protect when delete records

rkaria

Registered User.
Local time
Today, 21:39
Joined
Nov 19, 2009
Messages
48
Hi

I am trying to write the code so when a user deletes a record they get prompt msg box to enter password.

I have the below to delete the record but Im not sure how to get a prompt to enter password then if the correct one is entered to delete the record and if it isnt it will say wrong password can not delete.

Any advise

Thanks
rkaria

Private Sub Command120_Click()
On Error GoTo Err_Command120_Click

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Exit_Command120_Click:
Exit Sub
Err_Command120_Click:
MsgBox Err.Description
Resume Exit_Command120_Click
End Sub
 
If you have a log in screen you should be able to detemine who can and cannot delete records. That way you can disable the delete button if they do not have the rights to delete.

David
 
Even if they do not log in to the Database you may still be able to use their network login using the Environ("username") function, assuming they have to log onto the network!

If not then you can simply password protect your delete button. Place this code in a new module (this will mask the password entered) -

Code:
Option Compare Database
Option Explicit
' --- Global Constants (Messages) ------------------------------------
Global gMsgText As String 'Text in MsgBox() and InputBox() functions
Global gMsgType As Integer 'Type in MsgBox() and InputBox() functions
Global gMsgTitle As String 'Title for MsgBox() and InputBox() function
Global gStatusText As String 'Status bar text used in Application.Echo method
' API set A:
' Used by the callback process (TimerProc) to hook into
' the InputBox window
' Ref: [URL]http://pub13.ezboard.com/fvisualbasicexplorervbtips.showMessage?topicID=314.topic[/URL]
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SetTimer& Lib "user32" _
(ByVal hwnd&, ByVal nIDEvent&, ByVal uElapse&, ByVal _
lpTimerFunc&)
 
Public Declare Function KillTimer& Lib "user32" _
(ByVal hwnd&, ByVal nIDEvent&)
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
' Constants for API set A
Const EM_SETPASSWORDCHAR = &HCC
Public Const NV_INPUTBOX As Long = &H5000&
Public Function TimerProc(ByVal lHwnd&, ByVal uMsg&, _
ByVal lIDEvent&, ByVal lDWTime&) As Long
Dim lTemp As Long
' This function allows for a mask character on an inputbox
' ' Usage (Replace anything between [] with valid names from your project):
' From a form or module:
' 1. Declare a Long variable
' 2. Call the timer function: [variable] = SetTimer([form].Hwnd, NV_INPUTBOX, [elapsed time], AddressOf [function name])
' 2b. Example usage from a form: lTemp = SetTimer(Me.Hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
' 3. Create your InputBox as usual
 
Dim lEditHwnd As Long
 
' Find a handle to the InputBox window, then to the textbox
' the user types in (Known as "Edit")
' ' **This part is VERY important, here is how the FindWindowEx call should look:
' **Only change the parameters that are enclosed in [ ] in the following example
lTemp = FindWindowEx(FindWindow("#32770", "[gMsgText]"), 0, "Edit", "")
lEditHwnd = FindWindowEx(FindWindow("#32770", gMsgTitle), 0, "Edit", "")
 
' Send the mask character to the target InputBox when the user types
' The mask character in this sample is the Asc("*") - the "*" can be changed
' to whatever you like.
 
Call SendMessage(lEditHwnd, EM_SETPASSWORDCHAR, Asc("#"), 0)
' Destroy the timer object when done (The user clicks OK or Cancel from the InputBox)
KillTimer lHwnd, lIDEvent
End Function

Then place this code in your Command buttons OnClick event -

Code:
lTemp = SetTimer(Me.hwnd, NV_INPUTBOX, 1, AddressOf TimerProc)
sPwd = InputBox(gMsgText, gMsgTitle)
MsgBox "the password you entered was: " & sPwd
 
'Check to see if there is any entry made to input box, or if
'cancel button is pressed. 
    If sPwd = "" Or sPwd = Empty Then
        MsgBox "No Input Provided", vbInformation, "Required Data"
        Exit Sub
    End If
 
    'If correct password is entered dowhatever
    'If incorrect password entered give message and exit
 
    If sPwd = "YOURPASSWORDHERE" Then
 
    dowhatever (your delete code)
 
    Else
    Msgbox "Sorry, you do not have access to perform this operation", _
               vbOKOnly, "Important Information"
 
    End If
 
If you have a log in screen you should be able to detemine who can and cannot delete records. That way you can disable the delete button if they do not have the rights to delete.

David

Thanks David, but they dont log into the database.
 
[/code][/quote]

Wow thats great DBDamo, I will try it this afternoon
Thanks
Rkaria
 
Great form password,

How do I have text in my first input box because its just blank?
 

Users who are viewing this thread

Back
Top Bottom