Page 1 of 1
ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบด้วย ค่ะ
Posted: Wed Aug 26, 2020 3:31 pm
by thinatda
Code: Select all
Dim mFields As String: mFields = ""
If Usernames.Value = "" Then mFields = mFields & "Username" & vbNewLine
If passwords.Value = "" Then mFields = mFields & "password" & vbNewLine
If mFields <> "" Then
MsgBox "กรุณากรอกข้อมูลเข้าสู่ระบบ" & vbNewLine & mFields, vbCritical, mTitel
Else
Dim uSH As Worksheet: Set uSH = ThisWorkbook.Sheets("Login")
Dim isExist As Boolean: isExist = False
Dim wpassword As String: wpassword = ""
For c = 2 To uSH.Cells(Rows.Count, 2).End(xlUp).Row
If uSH.Range("A" & c).Value = Usernames.Value Then
isExist = True
wpassword = uSH.Range("B" & c).Value
Loginnames = uSH.Range("C" & c).Value
Exit For
End If
Next c
If isExist = False Then
MsgBox "คุณกรอก Username ผิด", vbCritical, mTitel
Usernames.Value = ""
passwords.Value = ""
Usernames.SetFocus
Else
If passwords.Value <> wpassword Then
MsgBox "คุณกรอก password ผิด", vbCritical, mTitel
Usernames.Value = ""
passwords.Value = ""
Usernames.SetFocus
Else
MsgBox "Welcome", vbInformation, mTitel
Unload Me
ผู้ใช้งาน.Show
End If
End If
End If
Re: ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบด้วย ค่ะ
Posted: Wed Aug 26, 2020 5:29 pm
by snasui

กรุณาปลด Password ของ VBE แล้วแนบไฟล์มาอีกรอบ จะได้สะดวกในการตรวจสอบ Code ครับ
Re: ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบด้วย ค่ะ
Posted: Thu Aug 27, 2020 8:46 am
by thinatda
snasui wrote: Wed Aug 26, 2020 5:29 pm

กรุณาปลด Password ของ VBE แล้วแนบไฟล์มาอีกรอบ จะได้สะดวกในการตรวจสอบ Code ครับ
ปลดแล้วค่ะ
Re: ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบด้วย ค่ะ
Posted: Thu Aug 27, 2020 9:26 am
by logic
เดาว่าแบบนี้ครับ
Code: Select all
'...
If passwords.Value <> wpassword Then
MsgBox "คุณกรอก password ผิด", vbCritical, mTitel
Usernames.Value = ""
passwords.Value = ""
Usernames.SetFocus
Else
MsgBox "Welcome", vbInformation, mTitel
uSH.Range("e" & c).Value2 = Date
uSH.Range("f" & c).Value2 = Time
Unload Me
ผู้ใช้งาน.Show
End If
'...
Re: ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบด้วย ค่ะ
Posted: Thu Aug 27, 2020 10:57 am
by thinatda
logic wrote: Thu Aug 27, 2020 9:26 am
เดาว่าแบบนี้ครับ
Code: Select all
'...
If passwords.Value <> wpassword Then
MsgBox "คุณกรอก password ผิด", vbCritical, mTitel
Usernames.Value = ""
passwords.Value = ""
Usernames.SetFocus
Else
MsgBox "Welcome", vbInformation, mTitel
uSH.Range("e" & c).Value2 = Date
uSH.Range("f" & c).Value2 = Time
Unload Me
ผู้ใช้งาน.Show
End If
'...
ได้แล้วค่ะ แล้วก้ต้องการให้ไปบันทึกอีกsheet นึงค่ะ
Code: Select all
Dim lRow As Long: lRow = 0
lRow = uSH.Cells(Rows.Count, 2).End(xlUp).Row + 1
uSH.Range("G" & lRow).Value2 = Date
uSH.Range("H" & lRow).Value2 = Time
Unload Me
¼Ùéãªé§Ò¹.Show
[code]
ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบไปsheetอื่นค่ะ
Posted: Thu Aug 27, 2020 2:25 pm
by thinatda
Code: Select all
Dim mFields As String: mFields = ""
If Usernames.Value = "" Then mFields = mFields & "Username" & vbNewLine
If passwords.Value = "" Then mFields = mFields & "password" & vbNewLine
If mFields <> "" Then
MsgBox "กรุณากรอกข้อมูลเข้าสู่ระบบ" & vbNewLine & mFields, vbCritical, mTitel
Else
Dim uSH As Worksheet: Set uSH = ThisWorkbook.Sheets("Login")
Dim isExist As Boolean: isExist = False
Dim wpassword As String: wpassword = ""
For c = 2 To uSH.Cells(Rows.Count, 2).End(xlUp).Row
If uSH.Range("A" & c).Value = Usernames.Value Then
isExist = True
wpassword = uSH.Range("B" & c).Value
Loginnames = uSH.Range("C" & c).Value
Exit For
End If
Next c
If isExist = False Then
MsgBox "คุณกรอก Username ผิด", vbCritical, mTitel
Usernames.Value = ""
passwords.Value = ""
Usernames.SetFocus
Else
If passwords.Value <> wpassword Then
MsgBox "คุณกรอก password ผิด", vbCritical, mTitel
Usernames.Value = ""
passwords.Value = ""
Usernames.SetFocus
Else
MsgBox "Welcome", vbInformation, mTitel
Dim lRow As Long: lRow = 0
lRow = uSH.Cells(Rows.Count, 2).End(xlUp).Row + 1
uSH.Range("G" & c).Value2 = Date
uSH.Range("H" & c).Value2 = Time
Unload Me
ผู้ใช้งาน.Show
End If
End If
End If
Re: ต้องการให้กดเข้าสู้ระบบแล้วให้บันทึกเวลาเข้าสู่ระบบด้วย ค่ะ
Posted: Thu Aug 27, 2020 3:04 pm
by snasui

เรื่องเดียวกันไม่ควรเปิดกระทู้ใหม่ ให้ถามต่อเนื่องกันไปได้เลย หากผู้ตอบมีเวลาจะเข้ามาตอบให้เองครับ
ในการโพสต์กระทู้คำถาม กรุณาอธิบายประกอบว่าต้องการจะทำอะไร ที่ชีตไหน เซลล์ไหน ปัจจุบันเขียนไว้แล้วตรงไหน
ถ้ายังไม่เขียนกรุณาเขียนมาก่อนและถามถามเฉพาะที่ติดปัญหา กรุณางดโพสต์แค่หัวกระทู้แล้วแนบไฟล์ให้ผู้ตอบเข้าไปแกะคำถามเองครับ
สำหรับคำถามนี้เป็นการนำวันที่ นำเวลาไปแสดงที่ชีตอื่น ได้เขียน Code นั้นเอาไว้แล้วหรือไม่ ถ้ายัง กรุณาเขียนมาก่อน ถามกันเฉพาะที่ติดปัญหา ตัวอย่าง Code ก็ตามที่คุณ logic ตอบเอาไว้แล้วเพียงแต่อ้างไปยังชีตที่ต้องการวางค่าเท่านั้นครับ