Results 1 to 8 of 8
  1. #1
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150

    Validation Using Code

    HI



    Len([Text4])>=8 And Like "*[0-9]*" And Like "*[a-z]*" And Like "*[@=.^_$%!#&'`{|}*?~/-]*"


    above is the validation rule i used for a form. is there is a way to implement the above validation rule using vba code? if so how to do it?

    appreciate your help.

    Thanks in advance

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    why test for all this? Isnt it EVERY character on the keyboard?
    just test for : >=8

  3. #3
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi

    its for a password filed. i want user to user password which consist of letter,number and special characters.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,142
    Have a read here for some examples of testing password complexity : https://access-programmers.co.uk/for...d.php?t=283490
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,113
    Quote Originally Posted by Eranka View Post
    Hi

    its for a password filed. i want user to user password which consist of letter,number and special characters.
    Eranka
    Use the before update event to test for those criteria
    However I've already answered this exact question in detail as part of your previous thread about password validation.
    https://www.accessforums.net/showthr...956#post398956
    In fact in that thread you said you had tried it and that it 'worked great'
    Perhaps you have forgotten!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I see Colin has responded, but I found and adjusted some vba regex that might be useful to someone.

    Code:
    ' ----------------------------------------------------------------
    ' Procedure Name: ValidateUserPassword
    ' Purpose: Validate user supplied password. Must be 8 or more chars in length.
    '          Must start with letter or digit.
    '          Must contain an Upper and Lower case char, a Digit and a special character.
    '          Uses Regex --so needs a reference to scripting runtime
    '  --base found on internet----
    ' Procedure Kind: Function
    ' Procedure Access: Private
    ' Parameter s (String):
    ' Return Type: Boolean
    ' Author: Jack
    ' Date: 12-Jun-18
    ' ----------------------------------------------------------------
    Private Function ValidateUserPassword(s As String) As Boolean
    
        Dim strPattern As String
    
        strPattern = "(?=^.{8,}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s)[0-9a-zA-Z!*^?](?=.*[\+\-\_\\\`\/\,\;\:\!\~\@\#\$\%\&\^\}\{\[\]\.])"
    
        With CreateObject("VBScript.RegExp")
            .Global = False
            .MultiLine = False
            .IgnoreCase = False
            .Pattern = strPattern
            ValidateUserPassword = .Test(s)
        End With
    
    End Function
    Here is my test routine

    Code:
    Sub valpwd()
    'test routine
        Dim i As Integer
        Dim Valstring(7) As String
    10  Valstring(0) = "Abc88+"     ' too short false
    20  Valstring(1) = "AbcDEfg#"   ' no digit  false
    30  Valstring(2) = "ABCD1234_"  ' no lower case false
    40  Valstring(3) = "abcd1234_"  ' no upper case false
    50  Valstring(4) = "abCD1873"   ' no special char false
    60  Valstring(5) = "AcBd7#w1-%" ' valid true
    70  Valstring(6) = "12BcZ,.;:"  ' valid true
    80  Valstring(7) = "$2BcZ,.@8"  ' must start with letter or digit false
    
    90  For i = 0 To 7
    100     Debug.Print i & "  " & Valstring(i) & " " & ValidateUserPassword(Valstring(i))
    110 Next i
    End Sub
    And here is the output:

    Code:
    0  Abc88+ False
    1  AbcDEfg# False
    2  ABCD1234_ False
    3  abcd1234_ False
    4  abCD1873 False
    5  AcBd7#w1-% True
    6  12BcZ,.;: True
    7  $2BcZ,.@8 False
    Last edited by orange; 06-12-2018 at 11:23 AM. Reason: didn't include all output

  7. #7
    Eranka is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Dec 2017
    Posts
    150
    Hi Ridders


    sorry i really forgot. small thing

    Code:
    Private Sub Command7_Click()Dim StrSQL As String
    Dim rec As String
    Dim but As String
    Dim Ic As String
    
    
    Ic = DLookup("[QuestionAnswer]", "tblUser", "[ID] = " & Me.UserLogin)
    
    
    If IsNull(Me.Text10) Then
     MsgBox "Answer Cannot Be Empty"
     Me.Text10.SetFocus
    ElseIf IsNull(Me.Text4) Then
     MsgBox "Password Cannot Be Empty"
     Me.Text4.SetFocus
    ElseIf DCount("*", "tblUser", "[UserPassword]= '" & Me.Text4 & "'") Then  '> 0 Then
     MsgBox "Please set a new password. OLD PASSWORD CANNOT BE REUSED !!! "
    ElseIf (Text10.Value = Ic) Then
    'ElseIf (Text10.Value <> Ic) Then
     'MsgBox "Your answer could not be verified, please try again. If Not Please Contact The Administrator  "
    'Else
    StrSQL = "INSERT INTO tblUser (UserPassword) " & "VALUES ('" & Me.Text4 & "')"
    'DoCmd.RunCommand acCmdSaveRecord
    'CurrentDb.Execute "Update tblUser SET Pdate = Date() WHERE ID = " & Me.UserLogin
    MsgBox " Password Of " & Me.Text2 & " Updated Successfully !!!"
    rec = Me.Text2
    but = "Password Update"
    CurrentDb.Execute "INSERT INTO ActivityLog (User, Form_Name, Record_ID,Record_Name,Activity_Date,Activity_Time)" & " VALUES ('" & rec & "','" & but & "','" & Me.UserLogin & "','" & Me.Text2 & "',Now(),Now())"
    DoCmd.Close
    DoCmd.OpenForm "Login"
    Else
    MsgBox "Your answer you provided could not be verified, please try again. If Not Please Contact The Administrator  "
    End If
    End Sub

    above is the button click method im using. is there is way to call below method inside above code instead of calling inside beforeupdate event.

    Code:
    ValidatePwd Text4

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,113
    No. Use the before update event for your textbox for validation
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 06-16-2015, 03:52 AM
  2. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  3. Help with Validation code on exit event on a form
    By thebionicredneck2003 in forum Programming
    Replies: 2
    Last Post: 05-17-2013, 06:04 AM
  4. Data validation code, I need a better solution.
    By Phred in forum Programming
    Replies: 10
    Last Post: 10-26-2012, 03:26 PM
  5. Replies: 4
    Last Post: 05-24-2011, 08:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums