Given that all the fields in my form are locked during form_load. I created a button that will unlock all fields. But before it does that, I want that the database asks a password before proceeding with the unlocking for added data security. How can I do this with an InputBox? Or is there a better way to do this? What codes or event procedures should I use? Help!In MS Access VB, how can I make a password prompt when I unlock all the fields?
You create a small pop-up form with a text box called txtPW: the key property to set on the properties for this text box is Input Mask: when you click on the build button, Select ';password'; for this property
The OK button has the following code (the form's On Open event has some code too)
Dim NoOfTries as Long
Sub Form_Open()
聽 聽 聽NoOfTries = 3
End Sub
Sub cmdOK_Click()
聽 聽 聽If (NoOfTries = 0) then
聽 聽 聽聽 聽 聽MsgBox ';Access Denied';, vbCritical
聽 聽 聽聽 聽 聽DoCmd.Close acForm, ';FrmPW';
聽 聽 聽End If
聽聽聽聽聽聽If (Len (trim(txtPW) %26amp; '; ';) = 1) Then Exit Sub
聽 聽 聽If (Encrypt(txtPW) %26lt;%26gt; 98465) Then
聽 聽 聽 聽 聽 聽NoOfTries = NoOfTries -1
聽 聽 聽 聽 聽 聽txtPW=';';
聽 聽 聽 聽 聽 聽Exit Sub
聽 聽 聽Else
' place your code here to unlock fields in form frmData, eg
聽 聽 聽With Forms![frmData]
聽聽聽聽聽聽聽聽聽![txtField].Locked = False
聽聽聽聽聽聽聽聽聽![txtField].BackColor = %26amp;HDDDDFF ' indicate status
聽 聽 聽End With
聽 聽 聽End If
End Sub
Put this in a module and hide it 鈥?it can be found, but it's a first level; of security
Function Encrypt (PW as string)
聽 聽 聽Dim I as long
聽 聽 聽Dim N as long
聽 聽 聽N=1
聽 聽 聽For i = 1 To Len(PW)
聽 聽 聽 聽 聽 聽N = N * Asc(mid(PW,i,1))
聽 聽 聽Next i
End Function
I've used the name Encrypt as a form of documentation to show what's going on: change it to any other name such as 'f'
Finally, single step through this sub (in the same module)
Sub X()
聽聽聽N = encrypt(';yourpassword';)
End Sub
To find the code for your chosen PW 鈥?then delete the Sub
No comments:
Post a Comment