เรียน ถาม อ. BADMan ครับ
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 340   5
URL.หัวข้อ / URL
เรียน ถาม อ. BADMan ครับ

จากตัวอย่างที่อ. เคยให้ไว้ผมเอาไปแกะดูมีขอสงสัยอยากเรียนถามครับ

1. จากคำสั่งข้างล่างมีตัวแปรหลายตัวทีไม่ได้ประกาศชนิดของตัวแปรไว้แต่ไม่ฟ้อง Error แบบว่าสงสัยครับ
2. จากการลองทดสอบดู Form Login ของ อาจารย์นั้นจะรู้จักเฉพาะ User ที่มีการ Add ไว้ใน TBL-พนักงาน หากนอกเหนือจากนี้โปรแกรมจะไม่แจ้งอะไรเลย แบบว่า แก้โค๊ดให้ด้วยครับ ผมพยายามแล้วแต่ไม่ออก
3. ตัวผมเองได้ประยุกต์จากตัวอย่างของ อาจารย์เข้ากับตัวอย่างที่ผมมีอยู่ ของผมเองก็เจอปัญหาเหมือนกันครับ คือว่า โปรแกรมจะรู้จักแต่ Account Name คนแรกคนเดียว เท่านั้น คนอื่นไม่รู้จัก อันนี้ก็ตันเหมือนกันครับ ( Account ผมอยู่ที่ Form-Permission ครับ)


คำสั่งที่ฟอร์ม Login

Private Sub คำสั่ง2_Click()
Dim strPass As String, strSecret As String, strPassWord As String
On Error GoTo ExitNow

strSecret = "???????"
strPassWord = DLookup("????????", "??????", "???????? = [Text1]")
strPass = EncryptDecrypt(strPassWord, strSecret)

If text2 = strPass Then
LoginName = [text1]
Pwd = [text2]
Adm = DLookup("admin", "??????", "???????? = [Text1]")
UserName = DLookup("????????", "??????", "???????? = [Text1]")
DayService = DLookup("??????????????", "??????", "???????? = [Text1]")
BigStore = DLookup("?????????????", "??????", "???????? = [Text1]")
MidStore = DLookup("????????????", "??????", "???????? = [Text1]")
Store = DLookup("?????????????????", "??????", "???????? = [Text1]")
Check = DLookup("???????", "??????", "???????? = [Text1]")
Tl = DLookup("?????????", "??????", "???????? = [Text1]")
Edt = DLookup("?????", "??????", "???????? = [Text1]")

DoCmd.OpenForm "???????", acNormal, , , acFormReadOnly, acWindowNormal
[Forms]![???????]![Text0] = UserName
[Forms]![???????]![text1] = LoginName
[Forms]![???????]![text2] = Pwd
DoCmd.Close acForm, "login", acSaveNo

Else
If PACom <= 1 Then
MsgBox "????????????? ???? ???? ??????? !", vbOKOnly, "LOGIN"
text1 = ""
text2 = ""
text1.SetFocus
?????2.Enabled = False
PACom = PACom + 1
Else
MsgBox "??????????????????????..!", vbOKOnly, "LOGIN"
PACom = 0
DoCmd.Quit acQuitSaveNone
End If

End If

ExitNow:
Exit Sub

End Sub

ตัวอย่างของผมที่ประยุกต์ขึ้นมาครับ

Private Sub cmdOK_Click()
Dim strPass As String, strSecret As String, strPassWord As String
Dim User As String, LoginName As String, Pwd As String, ChkRound As String
ChkRound = 3
'Dim USR As Variant

strSecret = "???????"
strPassWord = DLookup("USER_PASS", "TBL_USER", "USER_NAME = [USER_NAME]")
strPass = EncryptDecrypt(strPassWord, strSecret)

MsgBox "Password ?????????? = " & strPassWord & " Password ????????? = " & strPass


If FillUserPass = strPass Then
' If strPass = DLookup("USERNAME", "TBL_USER", "USER_NAME = [FillUserPass]") Then

MsgBox "strPass = " & strPass & " FillUserPass = " & FillUserPass

User = DLookup("USERNAME", "TBL_USER", "USER_NAME = [USER_NAME]")
LoginName = [USER_NAME]
Pwd = [FillUserPass]

' UserLogin = DLookup("USERNAME", "TBL_USER", "USER_NAME = [USER_NAME]")
' BelongToAdmin = DLookup("USER_ADMIN", "TBL_USER", "USER_NAME = [USER_NAME]")

DoCmd.OpenForm "MainMenu", acNormal, , , acFormReadOnly, acWindowNormal
[Forms]![MainMenu]![ShowName] = User
[Forms]![MainMenu]![ShowUser] = LoginName
[Forms]![MainMenu]![ShowPassword] = Pwd

' DoCmd.Close acForm, "frmlogin1", acSaveNo

DoCmd.Close acForm, "frmlogin", acSaveNo
DoCmd.OpenForm "MainMenu", acNormal, , , acFormReadOnly, acWindowNormal

Else
Beep
If PACom <= 1 Then
MsgBox "????????????? ???? ???? ??????? ! " & ChkRound & "", vbOKOnly, "??????????.."
FillUserPass = ""
FillUserPass = ""
FillUserPass.SetFocus
'?????2.Enabled = False
PACom = PACom + 1
ChkRound = ChkRound - PACom
Else
MsgBox "??????????????????????..!", vbOKOnly, "??????????.."
PACom = 0
DoCmd.Close
' DoCmd.Quit acQuitSaveNone
End If
End If

End Sub

ผมได้แนบไฟล์มาให้ดูด้วยครับ

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

1 @R02170
ลองดูตัวอย่างนี้ครับ ผมแก้ให้แล้ว..
2 @R02176
ตัวอย่างแก้ไขอีกครั้งจากตัวอย่างที่แล้วครับ...
1. ต้องขอโทษด้วยที่ไม่ละเอียด เพราะตัวอย่างที่แล้วยังไม่สามารถ Login ชื่ออื่นๆได้
2. ตัวแปรหลายตัวที่คุณไม่เห็นประกาศตัวแปรไว้เพราะผมประกาศไว้ใน Module เป็นชนิด Global
3 @R02187
ขอรบกวนอีกรอบครับ อ. BADMan

จาก Login ใน User ที่ไม่ได้กำหนดอยู่ใน TBL_USER โปรแกรมมันจะ Error ครับ ทำอย่างไรถึงจะปิด Error ตรงนี้ได้ครับ

4 @R02200
ก็ต้องดัก error สังเกตุว่า error code = 94 คือ Invalid Use of Null เมื่อดักแล้วจะให้ทำอะไรต่อ
ไปก็แล้วแต่เราครับ.. ลองดูจากตัวอย่าง..
5 @R02206
ขอบคุณมากครับ อ. BADMan
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0832s