เอามาฝากครับ Login User password พื้นฐาน และขอถามเ
กระทู้เก่าบอร์ด อ.Yeadram

 3,620   18
URL.หัวข้อ / URL
เอามาฝากครับ Login User password พื้นฐาน และขอถามเ

เป็นผู้ขอมาเยอะ ขอเป็นผู้ให้บ้างครับ ^^ มือใหม่อาจได้ใช้ประโยชน์ครับ

1 - สร้างฟอร์ม Login ขึ้นมา
2 - จัดหน้าตาแล้ววาง บล็อกข้อความ สองอันคือ Username และ Password
3 - ตั้งค่า Propertie ทั้งสองอันตรงหัวข้อ Other ที่ Name ให้ใส่ชื่อให้ตรงกับชื่อ บล็อกข้อความ
4 - สร้างปุ่มขึ้นมาแล้ว Propertie ไปที่ Event เลือกตรง On click และใส่โคดวีบี

Private Sub Command5_Click()
Username.SetFocus
If Username = "user1" And Password = "user1" Then
MsgBox "Access Granted", vbInformation, "CD Shop"
MsgBox "Welcome", vbInformation, "CD Shop"
DoCmd.Close
DoCmd.OpenForm "F_Switchboard"
Else
MsgBox "Please re-enter your Username and Password."
End If



และขอถามเพิ่มเติมครับพอดีผมได้โคดมา คือมันจะนับถ้าล็อกอินไม่ผ่าน 3 ครั้งมันจะปิด โคดนี้ครับที่ได้มา

Private intLogonAttempts As Integer
Private Sub cmdLogin_Click() intLogonAttempts = intLogonAttempts + 1 If intLogonAttempts > 3 Then MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!" Application.Quit End If
End Sub



แต่ไม่รู้ว่าจะเอาไปใช้กับอันเดิมยังไง ต้องปรับยังไงบ้างครับผม

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

1 @R15863
เข้าใจว่าปุ่ม Command5 คือปุ่มกดให้ผู้ใช้ Login ใช่ไหมครับ

Private Sub Command5_Click()
   Static intLogonAttempts As Integer

   If Username = "user1" And Password = "user1" Then
      intLogonAttempts = 0
      MsgBox "Access Granted", vbInformation, "CD Shop"
      MsgBox "Welcome", vbInformation, "CD Shop"
      DoCmd.Close
      DoCmd.OpenForm "F_Switchboard"
   End If
   
   intLogonAttempts = intLogonAttempts + 1
   If intLogonAttempts >= 3 then
      MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
      Application.Quit
   End If

   MsgBox "Please re-enter your Username and Password."
   Username.SetFocus
End If
2 @R15865
ไม่ได้ครับผม มัน error ตัวแดงอะครั

Private Sub Command8_Click()
Username.SetFocus
If Username = "user" And Password = "pass" Then
MsgBox "ÂÔ¹´Õµé͹ÃѺÊÙèÃкººÑ¹·Ö¡¢éÍÁÙÅ"
DoCmd.Close
DoCmd.OpenForm "main"
Else
MsgBox "¡ÃسÒãÊè ª×èÍáÅÐÃËÑÊ ãËéÙ¡µéÍ"
End If

intLogonAttempts? = intLogonAttempts? + 1 If intLogonAttempts? >= 3 then


      MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
      Application.Quit
   End If

   MsgBox "Please re-enter your Username and Password."
   Username.SetFocus
End If
End Sub
3 @R15866
intLogonAttempts = intLogonAttempts + 1
และ
If intLogonAttempts >= 3 then

ต้องคนละบรรทัดนะครับ
4 @R15874
ลองแล้วครับ ไม่ได้ครับผม ผมก็อบที่ทำให้ข้างบนไปวางก็เหมือนเดิมเลยครับ ตัวแดงเลยครับผม
5 @R15875
ต้องเอาตัว ? ออกครับ ตอนนี้ได้แล้วครับ

แต่มันก็ไม่นับให้ครับ แค่เตือนให้ใส่ใหม่ตลอดเลยครับ ไม่ยอมปิดเมื่อครบ 3 ครับ
6 @R15876
มันควรจะได้นะครับ
คุณสุโคยเอาโค้ที่เขียนมาแสดงให้ดูหน่อยครับ
7 @R15877
Private Sub Command8_Click()
Username.SetFocus
If Username = "user" And Password = "pass" Then
MsgBox "ÂÔ¹´Õµé͹ÃѺÊÙèÃкººÑ¹·Ö¡¢éÍÁÙÅ"
DoCmd.Close
DoCmd.OpenForm "main"

End If

intLogonAttempts = intLogonAttempts + 1
   If intLogonAttempts >= 3 Then
      MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
      Application.Quit
   End If

   MsgBox "¡ÃسÒãÊè ª×èÍáÅÐÃËÑÊ ãËéÙ¡µéÍ"
   Username.SetFocus

End Sub


อันนี้เลยครับ
8 @R15881
คุณลืมประกาศตัวแปรแบบ Static บรรทัดแรกไปหรือเปล่าครับ

Static intLogonAttempts As Integer
9 @R15885
อั๊ยยะ ใช่เลยครับ มิน่าละ มันถึงไม่ปิด หิๆๆขอบคุณมากๆครับ
10 @R15886
มันใช้ได้แบบ งง ตัวเองครับ

ลองใส่รหัสผิดสองครั้ง แล้วครั้งที่สามใส่ถูก มันก็เข้าหน้าต่อไป แต่ดันมีข้อความเตือนว่า เข้าสู่ระบบเกิน สามครั้งแล้วปิดโปรแกรมครับ

Private Sub Command8_Click()

Static intLogonAttempts As Integer
intLogonAttempts = intLogonAttempts + 1
   
Username.SetFocus
If Username = "user" And Password = "pass" Then
MsgBox "ยินดีต้อนรับสู่ระบบบันทึกข้อมูล"
DoCmd.Close
DoCmd.OpenForm "main"
Else
MsgBox "กรุณาใส่ ชื่อและรหัส ให้ถูกต้อง"
End If

    If intLogonAttempts >= 3 Then
      MsgBox "คุณพยายามเข้าระบบเกินสามครั้ง กรุณาติดต่อผู้ดูแลระบบ", vbCritical, "ปิดโปรแกรม"
      Application.Quit
   End If

End Sub
11 @R15890
ใช่แฮะ โค้ดผมตกหล่น เพิ่ม Exit Sub ไปเป็น

DoCmd.OpenForm "main"
Exit Sub
12 @R15892

มันก็ยังบ่อได้สักเตื้อ มันเป็นจักอี้จักอั้น

ตอนนี้บ่อฮู้บ่อหันละก่ะ


Private Sub Command8_Click()
Username.SetFocus
If Username = "user" And Password = "pass" Then
MsgBox "ยินดีต้อนรับสู่ระบบบันทึกข้อมูล"
DoCmd.Close
DoCmd.OpenForm "main"
Else
MsgBox "กรุณาใส่ ชื่อและรหัส ให้ถูกต้อง"
End If
Static intLogonAttempts As Integer
intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts >= 3 Then
      MsgBox "คุณพยายามเข้าระบบเกินสามครั้ง กรุณาติดต่อผู้ดูแลระบบ", vbCritical, "ปิดโปรแกรม"
      Application.Quit
   End If
DoCmd.OpenForm "main"
End Sub


13 @R15893
ไม่เห็นคุณเขียนอย่างที่ผมตอบเลย
14 @R15894
ย้ายบรรทัดนี้
intLogonAttempts = intLogonAttempts + 1
ไปหลัง Else ครับ
15 @R15895
ดูผิด page ครับ code เปลี่ยนไปแล้ว
ยกเลิกคำตอบไปก่อนครับ
16 @R15896

คุณ สันติสุข จ้าว ข้าจ้าวบ่อหัน โค้ดบั๋นทัดนั๋นเลยจ้าว
รบกวนอ้ายป่าวอีกทีจ้าวววว
17 @R15897
ใส่ตามนี้ครับ

Private Sub Command8_Click()
    username.SetFocus
    If username = "user" And password = "pass" Then
        Msgbox "ยินดีต้อนรับสู่ระบบบันทึกข้อมูล"
        DoCmd.Close
        DoCmd.OpenForm "main"
        Exit Sub
    Else
        Msgbox "กรุณาใส่ ชื่อและรหัส ให้ถูกต้อง"
    End If
    Static intLogonAttempts As Integer
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts >= 3 Then
        Msgbox "คุณพยายามเข้าระบบเกินสามครั้ง กรุณาติดต่อผู้ดูแลระบบ", vbCritical, "ปิดโปรแกรม"
        Application.Quit
    End If
End Sub
18 @R15902
ขอบคุณอ้ายป่าวจั๊กหลายๆ ได้แล้วจ้าววว
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.1611s