I have a volunteer database and having trouble with genuine password protections. I have a "delete" button with this current code under Build Event:

Private Sub delete_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.SetWarnings False
If MsgBox("Delete this VounteerRecord. Are you sure?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
DepartmentName.SetFocus
End If
Exit_delete_Click:
DoCmd.SetWarnings True
Exit Sub
Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_delete_Click
End Sub

Am I able to add a password protect code for admin user? If so, where and how do I put it in here to work properly I already tried and I can't debug it to work properly. Please help =(

indonesia speaking..?

You can obtain the password with an inputbox and decide from there.

Private Sub Command0_Click()

Dim answer As String

answer = InputBox("Enter password", "Admin")
    If answer = "admin123" Then
        MsgBox ("Administrator access")
    Else
        MsgBox ("Wrong Password")
    End If

End Sub

Be warned that applying this all over your db will give you a hard time changing the admin password. Think about using it in a function and calling that everytime or create a login form and use that to decide if admin access has been granted.

I tried to fit that somewhere on the code, but I keep have to debug. Where in the previous code is that able to fit in to work?

I am not sure what you mean by

Where in the previous code is that able to fit in to work?

I'm not so sure with your question but I think what you asking is to include a password on your code to protect it. well you can try this.

Dim password As String
password = "your password here"

' Now we are checking if the entered password do match
' With the main password or Admin password.

If txtpassword.Text = "your password here" Then
' The password is correct now you can do whatever you
' Want to do when the password entered is correct.

Else

 MsgBox("Incorrect password")
 txtpassword.Text = ""

 End if

You will put this code in the button that you will be using to login.

Do as Adam_K has stated and enter the code inside the if statement:

Define a password somewhere(in code or in db)

Private Sub delete_Click()
    On Error GoTo Err_cmdDelete_Click

    Dim answer as String = Inputbox("Please enter the password:","Password")

    If answer = MyPassword Then   
        DoCmd.SetWarnings False
        If MsgBox("Delete this VounteerRecord. Are you sure?", vbQuestion + vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
             DoCmd.RunCommand acCmdSelectRecord
             DoCmd.RunCommand acCmdDeleteRecord
             DepartmentName.SetFocus
         End If
         Exit_delete_Click:
             DoCmd.SetWarnings True
             Exit Sub
         Err_cmdDelete_Click:
             MsgBox Err.Description
             Resume Exit_delete_Click
     Else
         Exit Sub
     End If
 End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.