เรียน อาจารย์ ครับ
ขอบคุณมากครับ ได้แล้วครับ แต่ไฟล์ที่ต้องการให้เปิดยังไม่เปิดและไฟล์ username-password ปิด
ผมจึงเพิ่ม Code ต่อท้าย ดังนี้ ที่ Private Sub CommandButton1_Click() เพิ่มเป็น
Workbooks.Open filename:="G:\UserForm\login.xlsx"
Workbooks("username-password.xlsm").Close
ตามรายละเอียดใน Code ข้างล่าง
Code: Select all
Private Sub CommandButton1_Click()
Dim username As String
Dim password As String
'usernane = TextBox1.Text
'จาก Statement usernane = TextBox1.Text ให้เปลี่ยนเป็น username = TextBox1.Text
username = TextBox1.Text
password = TextBox2.Text
'if textbox1.text="abc" and textbox2.text="123"then
'msgbox("OK")
Dim info
'info = isWorkbooks.Open("G:\Userform\login.xlsx")
info = isworkbookopen("G:\Userform\login.xlsx")
'we open the work book
If info = False Then
Workbooks.Open ("G:\Userform\login.xlsx")
End If
Dim x As Integer
x = 2
Do While Cells(x, 1).Value <> ""
'If Cells(x, 1).Value = username And Cells(x, 2).Value = password Then
'จาก Statement If Cells(x, 1).Value = username And Cells(x, 2).Value = password Then เปลี่ยนเป็น If Cells(x, 1).Value = username And CStr(Cells(x, 2).Value) = password Then
If Cells(x, 1).Value = username And CStr(Cells(x, 2).Value) = password Then
MsgBox "Welcome"
Sheet1.Range("A1").Value = Date & " " & Time
Selection.NumberFormat = "d/m/YYYY h:mm am/pm"
UserForm1.Hide
Workbooks.Open filename:="G:\UserForm\login.xlsx"
Workbooks("username-password.xlsm").Close
End
Else
x = x + 1
End If
Loop
MsgBox "please check your username or password"
ActiveWorkbook.Close True
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
'else
'msgbox "wrong username or password"
'TextBox1.Text = ""
'TextBox2.Text = ""
'TextBox1.SetFocus
'endif
End Sub
จาก Code ข้างบน สิ่งเป็นปัญหา คือ ถ้ากรอก usernameหรือpassword ไม่ถูกต้อง ไฟล์ login ก็เปิด
ความต้องการ คือ ถ้ากรอก username หรือ password ไม่ถูกต้อง ให้ไฟล์ username-password ปิด
และไม่เปิดไฟล์ login ครับ
ขอความกรุณา แนะนำ ปรับปรุง Code ให้ด้วยครับ
You do not have the required permissions to view the files attached to this post.