Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple validation rules on a single field 1

Status
Not open for further replies.

DBAchick

Programmer
Apr 27, 2000
61
I am trying to validate the data that is being entered into a password field.  The password must be at least 5 characters, cannot be blank (null), cannot match the user login and cannot be the word password.  I have tried case statements, if statements, beforeupdate and afterupdate.  Any suggestions would be helpful at this point....
 
You can do a series of if stmts with msgboxes & goto's, such as (psuedocode!)<br><br>If length &lt; 5 then<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Min length 5. Try again.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;GoTo SubName_Exit:<br>End if<br>&nbsp;&nbsp;&nbsp;<br>If username = password then<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Can't be same as username.Try, try again...&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;GoTo SubName_Exit:<br>End if<br><br>blah blah<br>Subname_Exit:<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Function<br><br><br><br>
 
I would set that validation to take place on the beforeupdate event of a textbox on a password form. You can set Cancel=true for when you want the user to stay on the password form and try again. <br><br>For something a little more complex you can try this code snipet to allow a user to change their user password in the database. This is assuming you actually have user level security set up in the database.<br><br>Private Sub cmdchange_Click()<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim sMsg As String<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim wks As Workspace<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim serr As String<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;On Error GoTo cmdChange_click_err<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;Set wks = DBEngine(0)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If IsNull(txtOldPwd) Or IsNull(txtVerify) Then Exit Sub<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If IsNull(txtOldPwd) Then txtOldPwd = &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;sMsg = &quot;Your new password and the verification of your &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;sMsg = sMsg & &quot;new password do not match. &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;sMsg = sMsg & &quot;Please try again.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;If txtNewPwd &lt;&gt; txtVerify Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox sMsg, vbExclamation<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;wks.Users(CurrentUser).NewPassword txtOldPwd, txtNewPwd<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If txtNewPwd &lt;&gt; &quot;&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MsgBox &quot;Password successfully changed.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;txtOldPwd = Null<br>&nbsp;&nbsp;&nbsp;&nbsp;txtNewPwd = Null<br>&nbsp;&nbsp;&nbsp;&nbsp;txtVerify = Null<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>cmdChange_Click_Exit:<br>&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<br><br>cmdChange_click_err:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;serr = &quot;Cannot change this password.&nbsp;&nbsp;Please &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;serr = serr & &quot;ensure that you have &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;serr = serr & &quot;typed the old password correctly.&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;MsgBox serr, vbExclamation<br>&nbsp;&nbsp;&nbsp;&nbsp;Resume cmdChange_Click_Exit<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top