Well there's no way in the world (...not strictly true, but it'd be a lot of
work) that it's going to be updateable if it's hard coded in the code behind
a button.
Add another table (called Password maybe) just with two fields Password
(text) and ExpiryDate (date). Add a single record with a password and when
you want it to expire. Replace
If strpwd = conGoodPwd Then
GetPwd = True
Exit For
End If
with (aircode)...
dim d as date, resp as integer, newpwd as string
getpwd=false
if strpwd=dlookup("[Password]","Password") then
d=dlookup("[ExpiryDate]","Password")
if date()<=d then
if datediff("d",date(),d)<3 then
resp=msgbox("Going to expire. Change it?", _
vbyesno,"Update pwd")
if resp=vbyes then
newpwd=inputbox("Change to?")
'use dateadd to add however many days onto d, then
'run an update query to overwrite expirtydate with the new
'date and password to newpwd
endif
endif
getpwd=true
exit for
endif
endif
(note, by the way, that indenting Ifs and loops makes it a damn sight easier
to read.)
And it's still pointless. What will happen in real life will be that the
person who changes it will probably write the new password down on a post-it
note stuck to the screen. If they don't then they've just locked everybody
else out. Those that don't know about the shift key anyway.
Welly said:
Nope it is a standalone database on one computer but with multiple users
throughout the day.
The password is set to two of the buttons on the form with the following code
Function GetPwd() As Boolean
Dim strpwd As String
Const conGoodPwd As String = "Winter05"
Dim intMaxTries As Integer
For intMaxTries = 1 To 3
strpwd = InputBox("Enter Password")
If strpwd = "" Then
GetPwd = False
Exit For
End If
If strpwd = conGoodPwd Then
GetPwd = True
Exit For
End If
If MsgBox("Incorrect Password", vbExclamation + vbOKCancel, "Error") =
vbCancel Then
GetPwd = False
Exit For
End If
Next intMaxTries
End Function
Private Sub Command35_Click()
On Error GoTo Err_Command35_Click
Dim stDocName As String
stDocName = "mcrReports"
If GetPwd() Then
DoCmd.RunMacro stDocName
End If
Exit_Command35_Click:
Exit Sub
Err_Command35_Click:
MsgBox Err.Description
Resume Exit_Command35_Click
End Sub