ช่วยแก้ Code รหัสผ่านไม่ถูกต้องให้หน่อยคับ
กระทู้เก่าบอร์ด อ.Yeadram

 947   3
URL.หัวข้อ / URL
ช่วยแก้ Code รหัสผ่านไม่ถูกต้องให้หน่อยคับ

สวัสดีครับปัญหามีอยู่ว่า
-ทำหน้า Login ขึ้นมาแล้ว พอใส่รหัสผ่านผิดไม่ขึ้นข้อความเตือนเลยและต้องการ Code เพิ่มเติมกำหนดให้ใส่ผิดได้จำนวน 3 ครั้ง หากผิดอีกก็จะปิด หน้า Login ไป
-แต่พอใส่ User ผิดดันมีคำเตือนขึ้น

Code ที่มีปัญหาคับ
Private Sub cmdOK_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer

     With CodeContextObject
   If (IsNull(.txtUser) Or IsNull(.txtPWD)) Then
           Beep
           MsgBox "กรุณากรอง User Name และ Password ให้ครบด้วย!", vbExclamation, ""
           Exit Sub
      End If
End With                                                             

'*****************************************************************

strUser = Me.txtUser
If DCount("[UserPWD]", "tblUsers", "[UserName]='" & Me.txtUser & "'") > 0 Then
    strPWD = DLookup("[UserPWD]", "tblUsers", "[UserName]='" & Me.txtUser & "'")
    If strPWD = Me.txtPWD Then
        intUSL = DLookup("[SecurityGroup]", "tblUsers", "[UserName]='" & Me.txtUser & "'")

      Forms![frmStart].txtUN = strUser
      Forms![frmStart].txtUSL = intUSL
    
        Select Case intUSL
            Case 1
               DoCmd.OpenForm "applogo", acNormal      'Admin
               DoCmd.Restore
              
            Case 2
               DoCmd.OpenForm "applogo", acNormal, , , acFormReadOnly       
               DoCmd.Restore
            Case 3
               DoCmd.OpenForm "applogo", acNormal, , , acFormAdd              
               DoCmd.Restore
            Case 4
               DoCmd.OpenForm "applogo", acNormal, , , acFormEdit              
               DoCmd.Restore
        End Select
        DoCmd.Close acForm, "frmTestLogin", acSaveNo
    End If
   Else
   MsgBox "รหัสผ่านไม่ถูกต้อง กรุณาใส่รหัสใหม่ "
End If          
End Sub

ข้อมูลเพิ่มเติม
ตารางชื่อ tblUser ประกอบไปด้วย UserName , UserPWD , SecurityGroup
ในฟอร์มชื่อ frmTestLogin ประกอบด้วย
Textbox ชื่อ txtUser , txtPWD
ปุ่ม ขื่อ cmdCancel , cmdOK



3 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R19779
จริงๆ มันลดทอนโค๊ตลงได้นะครับ แต่เอาเป็นว่าผมเขียนเพิ่มเข้าไปแล้วกันนะครันจะได้ดูง่ายไม่ต่างจากของเดิม

Private Sub Command4_Click()
Dim strUser As String
Dim strPWD As String
Dim intUSL As Integer
Static ErrPWD As Integer

With CodeContextObject
   If (IsNull(.txtUser) Or IsNull(.txtPWD)) Then
           Beep
           MsgBox "กรุณากรอง User Name และ Password ให้ครบด้วย!", vbExclamation, ""
           Exit Sub
      End If
End With

'*****************************************************************
strUser = Me.txtUser
If DCount("[UserPWD]", "tblUsers", "[UserName]='" & Me.txtUser & "'") > 0 Then
    strPWD = DLookup("[UserPWD]", "tblUsers", "[UserName]='" & Me.txtUser & "'")
    If strPWD = Me.txtPWD Then
        intUSL = DLookup("[SecurityGroup]", "tblUsers", "[UserName]='" & Me.txtUser & "'")

      Forms![frmStart].txtUN = strUser
      Forms![frmStart].txtUSL = intUSL
     
        Select Case intUSL
            Case 1
               DoCmd.OpenForm "applogo", acNormal      'Admin
               DoCmd.Restore
            Case 2
               DoCmd.OpenForm "applogo", acNormal, , , acFormReadOnly
               DoCmd.Restore
            Case 3
               DoCmd.OpenForm "applogo", acNormal, , , acFormAdd
               DoCmd.Restore
            Case 4
               DoCmd.OpenForm "applogo", acNormal, , , acFormEdit
               DoCmd.Restore
        End Select
        DoCmd.Close acForm, "frmTestLogin", acSaveNo
    Else
        ErrPWD = ErrPWD + 1
        MsgBox "รหัสผ่านไม่ถูกต้อง กรุณาใส่รหัสใหม่ " & "(" & ErrPWD & ")"
        If ErrPWD > 2 Then DoCmd.Close acForm, Me.Name, acSaveNo

    End If
Else
    ErrPWD = ErrPWD + 1
   MsgBox "รหัสผ่านไม่ถูกต้อง กรุณาใส่รหัสใหม่ " & "(" & ErrPWD & ")"
   If ErrPWD > 2 Then DoCmd.Close acForm, Me.Name, acSaveNo

End If
End Sub

ประมาณนี้ปรับใช้ครับ
2 @R19780
ขอบคุณมากๆ เลยคับ ใช่ได้ดีมากเลย
3 @R19782
รบกวนอาจารย์ TTT ลดทอนโค๊ดให้หน่อยได้มั้ยครับ

อยากทราบเผื่อไว้ประยุกต์ใช้ต่อครับ

ขอบคุณครับ
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.3161s