Page 2 of 3

Re: แสดงข้อมูลใน Listbox

Posted: Thu Nov 16, 2017 6:02 pm
by Benmore
เข้าใจค่ะ แต่ที่ต้องการคือข้อมูลในชีทการเบิกคือชีท9 ค่ะ ไม่ใช้ข้อมูลในชีท6

Re: แสดงข้อมูลใน Listbox

Posted: Thu Nov 16, 2017 6:05 pm
by snasui
:D Code ที่ถามมานั้นเป็นการเข้าถึง Sheet6 ไม่เกี่ยวกับ Sheet9 ครับ ช่วยสรุปปัญหานี้มาใหม่ จะได้ลำดับความเข้าใจใหม่ครับ

Code ใดมีปัญหา ตัวอย่างข้อมูลทดสอบคืออะไร ต้องการคำตอบเป็นอย่างไร ถ้าเป็นเรื่องเดียวกันกับกระทู้อื่นต้องไปถามต่อในกระทู้นั้น Procedure เดียวกัน ต้องไม่แยกถามหลายกระทู้ครับ

Re: แสดงข้อมูลใน Listbox

Posted: Thu Nov 16, 2017 6:19 pm
by Benmore
กระทู้นี้เป็นกระทู้ที่ต้องการให้ค้นหาข้อมูลการเบิกด้วยวันที่ กับ รหัสค่ะ
ตัวอย่าง :ard: :ard: :ard: :ard: :ard: :ard: :ard: :ard: :ard:
ชีทการเบิก(ชีท9)
รหัส 009 |นาย ก |วันที่ 16 srptember 2017 | เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
รหัส 010 |นาย ข |วันที่ 16 srptember 2017 | เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
รหัส 009 |นาย ก |วันที่ 17 srptember 2017 | เบิก เสื้อ 2 ตัว กางเกง 2 ตัว
รหัส 009 |นาย ก |วันที่ 18 srptember 2017 | เบิก เสื้อ 3 ตัว กางเกง 3 ตัว
:ard:
Userform1
เมื่อใส่วันที่ 16 srptember 2017 แล้วกดปุ่มค้นหาก็จะแสดงข้อมูลใน listbox
:arrow: รหัส 009 |นาย ก |เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
:arrow: รหัส 010 |นาย ข |เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
เมื่อใส่รหัส 009 แล้วกดปุ่มค้นหาก็จะแสดงข้อมูลใน listbox
:arrow: วันที่ 16 srptember 2017 | เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
:arrow: วันที่ 17 srptember 2017 | เบิก เสื้อ 2 ตัว กางเกง 2 ตัว
:arrow: วันที่ 18 srptember 2017 | เบิก เสื้อ 3 ตัว กางเกง 3 ตัว
แสดงเป็นตารางเพื่อแก้ไขข้อมูลในขั้นตอนถัดไปได้ค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Thu Nov 16, 2017 7:22 pm
by snasui
Benmore wrote:กระทู้นี้เป็นกระทู้ที่ต้องการให้ค้นหาข้อมูลการเบิกด้วยวันที่ กับ รหัสค่ะ
ตัวอย่าง :ard: :ard: :ard: :ard: :ard: :ard: :ard: :ard: :ard:
ชีทการเบิก(ชีท9)
รหัส 009 |นาย ก |วันที่ 16 srptember 2017 | เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
รหัส 010 |นาย ข |วันที่ 16 srptember 2017 | เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
รหัส 009 |นาย ก |วันที่ 17 srptember 2017 | เบิก เสื้อ 2 ตัว กางเกง 2 ตัว
รหัส 009 |นาย ก |วันที่ 18 srptember 2017 | เบิก เสื้อ 3 ตัว กางเกง 3 ตัว
:ard:
Userform1
เมื่อใส่วันที่ 16 srptember 2017 แล้วกดปุ่มค้นหาก็จะแสดงข้อมูลใน listbox
:arrow: รหัส 009 |นาย ก |เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
:arrow: รหัส 010 |นาย ข |เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
เมื่อใส่รหัส 009 แล้วกดปุ่มค้นหาก็จะแสดงข้อมูลใน listbox
:arrow: วันที่ 16 srptember 2017 | เบิก เสื้อ 1 ตัว กางเกง 1 ตัว
:arrow: วันที่ 17 srptember 2017 | เบิก เสื้อ 2 ตัว กางเกง 2 ตัว
:arrow: วันที่ 18 srptember 2017 | เบิก เสื้อ 3 ตัว กางเกง 3 ตัว
แสดงเป็นตารางเพื่อแก้ไขข้อมูลในขั้นตอนถัดไปได้ค่ะ
:D แนบไฟล์ล่าสุดมาใหม่ครับ Code แจ้ง Procedure ปัญหา บรรทัดที่ติดปัญหามาอีกรอบ ที่เคยถามในตอนต้นไม่เกี่ยวกับ Sheet9 แต่เขียนเกี่ยวกับการเข้าถึงข้อมูลที่ Sheet6 ตามด้านล่างครับ
Benmore wrote:

Code: Select all

Private Sub btsearch1_Click()
   Dim found As Boolean
   Dim txt As String
   Dim r As Range
    Dim chkDate As Date
    On Error Resume Next
    Dim nRow As String
    For Each r In Sheet6.Columns(1).SpecialCells(xlCellTypeConstants)
    Sheet6.Activate
    chkDate = CDate(Applicion.Text(cmday & "/" & cmmonth & "/" & cmyear, "ddmmyyyy"))
    If Right(r.Value, 3) = Right(txtsearch1.Text, 3) Or r.Offset(0, 4).Value = chkDate Then
        nRow = r.row
        found = True
        Exit For
    End If
    Next r
    If found Then
        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
            MsgBox "กรุณาใส่ข้อมูลเป็นตัวเลข"
            Exit Sub
        End If
        If Err.Number = 91 Then
        TextBox1.RowSource = "txtsearch1.Text"
  TextBox7.Value = ""
    TextBox8.Value = ""
    TextBox9.Value = ""
    TextBox10.Value = ""
      End If
แก้ไขได้ประมาณนี้ค่ะ แต่ก็ยังรันไม่ได้ค่ะ ข้อมูลที่ค้นหาด้วยรหัสก็ไม่แสดงใน listbox เลยค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Thu Nov 16, 2017 11:36 pm
by Benmore
ข้อมูลทุกอย่าง ถูกบันทึกลงในชีท9ค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Fri Nov 17, 2017 6:47 am
by snasui
Benmore wrote:ข้อมูลทุกอย่าง ถูกบันทึกลงในชีท9ค่ะ
:D เมื่อต้องการบันทึกไปยัง Sheet9 ก็ต้องเขียน Code ให้บันทึกไปยัง Sheet9 ติดปัญหาแล้วเอามาถามกัน ใน Code ข้างต้นนี้เขียนเกียวกับ Sheet6 เกี่ยวกับการ Search สอดคล้องกับหัวกระทู้ที่เขียนว่า "แสดงข้อมูลใน Listbox" ไม่เกียวกับการบันทึก ตามที่ยกมาให้ดูในโพสต์ #24 :roll: ไม่เกี่ยวกับ Sheet9 แต่อย่างใด กรุณาทบทวนดูใหม่ครับ

Re: แสดงข้อมูลใน Listbox

Posted: Fri Nov 17, 2017 8:43 am
by Benmore
#24 เป็นการค้นหาข้อมูลค่ะ ไม่ใช่การบันทึกข้อมูล ให้ค้นหาข้อมูลในชีท 9 แล้วมาแสดงบน listbox ค่ะ
snasui wrote:
Benmore wrote:ข้อมูลทุกอย่าง ถูกบันทึกลงในชีท9ค่ะ
:D เมื่อต้องการบันทึกไปยัง Sheet9 ก็ต้องเขียน Code ให้บันทึกไปยัง Sheet9 ติดปัญหาแล้วเอามาถามกัน ใน Code ข้างต้นนี้เขียนเกียวกับ Sheet6 เกี่ยวกับการ Search สอดคล้องกับหัวกระทู้ที่เขียนว่า "แสดงข้อมูลใน Listbox" ไม่เกียวกับการบันทึก ตามที่ยกมาให้ดูในโพสต์ #24 :roll: ไม่เกี่ยวกับ Sheet9 แต่อย่างใด กรุณาทบทวนดูใหม่ครับ
#24 เป็นการค้นหาข้อมูลค่ะ ไม่ใช่การบันทึกข้อมูล ให้ค้นหาข้อมูลในชีท 9 แล้วมาแสดงบน listbox ค่ะ ไม่ได้มีคำถามเกี่ยวกับการบันทึกแต่อย่างใด มีแค่การแสดงข้อมูลใน Listbox ค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Fri Nov 17, 2017 8:56 am
by Benmore

Code: Select all

   Dim found As Boolean
   Dim txt As String
   Dim r As Range
    Dim chkDate As Date
    On Error Resume Next
    Dim nRow As String
    chkDate = DateSerial(cmyear, cmmonth.ListIndex + 1, cmday)
    Sheet9.Activate
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
    If Right(r.Value, 3) = Right(txtsearch1.Text, 3) Or r.Offset(0, 4).Value2 = CLng(chkDate) Then
        nRow = r.Row
        found = True
        Exit For
    End If
    Next r
    If found Then
        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
            MsgBox "¡ÃسÒãÊè¢éÍÁÙÅà»ç¹µÑÇàÅ¢"
            Exit Sub
        End If
ลองปรับโค้ดให้เชื่อมกับชีท 9 แล้วค่ะ แต่ก็ไม่มีข้อมูลแสดงใน listbox เลยค่ะ แล้วยังค้นหาด้วนวันที่ไม่ได้ค่ะพอกดค้นหาด้วยวันที่จะขึ้นแจ้งเตือนว่าให้ใส่ข้อมูลเป็นตัวเลขเหมือนกับถ้าเราใส่ข้อมูลที่ไม่ใช่ตัวเลขใน txtsearch ค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Fri Nov 17, 2017 7:06 pm
by snasui
Benmore wrote:ข้อมูลทุกอย่าง ถูกบันทึกลงในชีท9ค่ะ
:D เมื่อปัญหาคือการ Search ก็ไม่ควรกล่าวถึงการบันทึก แยกประเด็นกันให้ชัด การสอบถามควรมุ่งไปที่การอธิบายปัญหาที่เกิดจากการ Search เป็นหลักครับ

สรุปปัญหาคือต้องการค้นหาแล้วให้ข้อมูลแสดงใน ListBox ตัวอย่างการปรับ Code คือด้านล่าง

Code: Select all


'ค้นหา 1
Private Sub btsearch1_Click()
    'On Error Resume Next
    Dim found As Boolean
    Dim txt As String
    Dim r As Range
    Dim chkDate As Date
'    On Error Resume Next
    Dim nRow As String
    chkDate = DateSerial(cmyear, cmmonth.ListIndex + 1, cmday)
    Sheet9.Activate
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
        If Right(r.Value, 3) = Right(txtsearch1.Text, 3) Or r.Offset(0, 4).Value2 = CLng(chkDate) Then
        nRow = r.Row
        found = True
        Exit For
    End If
    Next r
    If found Then
    '        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
        '            MsgBox "กรุณาใส่ข้อมูลเป็นตัวเลข"
        '            Exit Sub
        '        End If
        If Err.Number = 91 Then
            TextBox1.RowSource = "txtsearch1.Text"
            TextBox7.Value = ""
            TextBox8.Value = ""
            TextBox9.Value = ""
            TextBox10.Value = ""
            'MsgBox "ไม่มีข้อมูล"
        End If
        TextBox7.Value = Cells(nRow, 1)
        TextBox8.Value = Cells(nRow, 2)
        TextBox9.Value = Cells(nRow, 3)
        TextBox10.Value = Cells(nRow, 4)
        txt = "Emp_ID : " & Cells(nRow, 1) & vbCrLf & _
            "Name : " & Cells(nRow, 2) & vbCrLf & _
            "Section : " & Cells(nRow, 3) & vbCrLf & _
            "Uniform_No : " & Cells(nRow, 4) & vbCrLf & _
            "Date : " & Cells(nRow, 5) & vbCrLf & _
            "Discription : " & Cells(nRow, 6) & vbCrLf & _
            "Reason : " & Cells(nRow, 7)
        ListBox1.AddItem txt
        Exit Sub
    Else
        MsgBox "ไม่มีข้อมูล"
    End If
    Sheet1.Activate
End Sub
โปรดสังเกตว่ามีการ Mark บรรทัดใดไปเป็น Comment บ้าง หากจะใช้จะต้องพิจารณาบรรทัดนั้นใหม่ อีกประการ ListBox ไม่สามารกแยกแสดงเป็นหลายบรรทัดด้วยการใช้ VbCrlf เหมือนเช่น TextBox ที่สามารถกำหนด Multiline ช่วยเพื่อแสดงข้อความที่คั่นด้วย VbCrlfเป็นหลายบรรทัดครับ

Re: แสดงข้อมูลใน Listbox

Posted: Sat Nov 18, 2017 4:22 pm
by Benmore
Benmore wrote:
snasui wrote:
Benmore wrote:ข้อมูลทุกอย่าง ถูกบันทึกลงในชีท9ค่ะ
:D เมื่อปัญหาคือการ Search ก็ไม่ควรกล่าวถึงการบันทึก แยกประเด็นกันให้ชัด การสอบถามควรมุ่งไปที่การอธิบายปัญหาที่เกิดจากการ Search เป็นหลักครับ

สรุปปัญหาคือต้องการค้นหาแล้วให้ข้อมูลแสดงใน ListBox ตัวอย่างการปรับ Code คือด้านล่าง

Code: Select all

แล้วต้องแก้ไขโค้ดตรงไหนเพิ่มค่ะ


'ค้นหา 1
Private Sub btsearch1_Click()
    'On Error Resume Next
    Dim found As Boolean 
    Dim txt As String
    Dim r As Range
    Dim chkDate As Date
'    On Error Resume Next
    Dim nRow As String
    chkDate = DateSerial(cmyear, cmmonth.ListIndex + 1, cmday)
    Sheet9.Activate
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
        If Right(r.Value, 3) = Right(txtsearch1.Text, 3) Or r.Offset(0, 4).Value2 = CLng(chkDate) Then
        nRow = r.Row
        found = True
        Exit For
    End If
    Next r
    If found Then
    '        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
        '            MsgBox "กรุณาใส่ข้อมูลเป็นตัวเลข"
        '            Exit Sub
        '        End If
        If Err.Number = 91 Then
            TextBox1.RowSource = "txtsearch1.Text"
            TextBox7.Value = ""
            TextBox8.Value = ""
            TextBox9.Value = ""
            TextBox10.Value = ""
            'MsgBox "ไม่มีข้อมูล"
        End If
        TextBox7.Value = Cells(nRow, 1)
        TextBox8.Value = Cells(nRow, 2)
        TextBox9.Value = Cells(nRow, 3)
        TextBox10.Value = Cells(nRow, 4)
        txt = "Emp_ID : " & Cells(nRow, 1) & vbCrLf & _
            "Name : " & Cells(nRow, 2) & vbCrLf & _
            "Section : " & Cells(nRow, 3) & vbCrLf & _
            "Uniform_No : " & Cells(nRow, 4) & vbCrLf & _
            "Date : " & Cells(nRow, 5) & vbCrLf & _
            "Discription : " & Cells(nRow, 6) & vbCrLf & _
            "Reason : " & Cells(nRow, 7)
        ListBox1.AddItem txt
        Exit Sub
    Else
        MsgBox "ไม่มีข้อมูล"
    End If
    Sheet1.Activate
End Sub
โปรดสังเกตว่ามีการ Mark บรรทัดใดไปเป็น Comment บ้าง หากจะใช้จะต้องพิจารณาบรรทัดนั้นใหม่ อีกประการ ListBox ไม่สามารกแยกแสดงเป็นหลายบรรทัดด้วยการใช้ VbCrlf เหมือนเช่น TextBox ที่สามารถกำหนด Multiline ช่วยเพื่อแสดงข้อความที่คั่นด้วย VbCrlfเป็นหลายบรรทัดครับ
ต้องแก้ไขโค้ดตรงไหนค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Sat Nov 18, 2017 4:52 pm
by snasui
Benmore wrote:ต้องแก้ไขโค้ดตรงไหนค่ะ
:D คำถามคืออะไรครับ กรุณาเขียนมาด้วยจะได้ทราบว่าพูดถึงประเด็นใด ถ้าเป็นเรื่องการแสดง ListBox เป็นหลายบรรทัดเหมือน TextBox จะทำเช่นนั้นไม่ได้ ไม่มี Propety นั้นที่เป็นของ ListBox ถ้าจะทำต้องกลับไปใช้ TextBox

การใช้ ListBox จะต้อง Add เป็นบรรทัดละ Item ไม่ใช่ 1 Item มีหลายบรรทัดครับ และไม่ว่าจะเป็นแบบ TextBox หรือ ListBox จำเป็นต้องเขียนหรือปรับ Code มาเองก่อนสมอไป ติดปัญหาแล้วค่อยถามกันครับ

Re: แสดงข้อมูลใน Listbox

Posted: Sat Nov 18, 2017 10:27 pm
by Benmore
ถ้าเลือกใช้แบบ textbox จะสามารถเลือกข้อมูลมาแก้ไข ลบ ได้หรือไม่ค่ะ

Re: แสดงข้อมูลใน Listbox

Posted: Sat Nov 18, 2017 11:59 pm
by snasui
:D การใช้ Code สามารถทำได้แทบทั้งสิ้น ขึ้นอยู่กับความสามารถของผู้เขียนเป็นหลักครับ

Re: แสดงข้อมูลใน Listbox

Posted: Mon Nov 20, 2017 4:19 pm
by Benmore
รบกวนช่วยดูโค้ดการค้นหาข้อมูลด้วยรหัสพร้อมกับวันที่ให้หน่อยค่ะ ตอนนี้ค้นหาได้โดยรหัสอย่างเดียวค่ะ
เช่น ค้นหา รหัส 02000009 วันที่ 20 November 2017
แสดง :arrow: การเบิกของของรหัส 02000002 ในวันที่ 20 November 2017 ถ้าไม่มีข้อมูลให้แสดงว่าไม่มีข้อมูล

Code: Select all

Private Sub btsearch1_Click()
On Error Resume Next
If txtsearch1.Value = "" Or cmday.Value = "" Or cmmonth.Value = "" Or cmyear.Value = "" Then
                MsgBox "¡ÃسÒãÊè¢éÍÁÙÅãËé¤Ãº"
                Combobox1.Value = ""
        Exit Sub
    End If
   Dim found As Boolean
   Dim txt As String
   Dim r As Range
    Dim chkDate As Date
    Dim nRow As String
    chkDate = DateSerial(cmyear, cmmonth.ListIndex + 1, cmday)
    Sheet9.Activate
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
    If Right(r.Value, 3) = Right(txtsearch1.Value, 3) Or r.Offset(0, 0).Value2 = CLng(chkDate) Then
        nRow = r.Row
        found = True
        Exit For
    End If
    Next r
    If found Then
        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
            MsgBox "¡ÃسÒãÊè¢éÍÁÙÅà»ç¹µÑÇàÅ¢"
            Exit Sub
        End If
        If Err.Number = 91 Then
        'TextBox1.RowSource = "txtsearch1.Text"
  TextBox7.Value = ""
    TextBox8.Value = ""
    TextBox9.Value = ""
    TextBox10.Value = ""
      TextBox11.Value = ""
         TextBox16.Value = ""
            TextBox17.Value = ""
        TextBox12.Value = ""
          TextBox13.Value = ""
    'MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
 TextBox7.Value = Cells(nRow, 1)
TextBox8.Value = Cells(nRow, 2)
    TextBox9.Value = Cells(nRow, 3)
    TextBox10.Value = Cells(nRow, 4)
      TextBox11.Value = Cells(nRow, 6)
      TextBox16.Value = Cells(nRow, 7)
      TextBox17.Value = Cells(nRow, 8)
        TextBox12.Value = Cells(nRow, 9)
          TextBox13.Value = Cells(nRow, 10)
     Exit Sub
     Else
       MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
    Sheet1.Activate
End Sub

Re: แสดงข้อมูลใน Listbox

Posted: Tue Nov 21, 2017 7:45 pm
by snasui
:D ตัวอย่างการค้นหา 2 เงื่อนไขพร้อมกันครับ

Code: Select all

'Other code
If Right(r.Value, 3) = Right(txtsearch1.Value, 3) And r.Offset(0, 4).Value2 = CLng(chkDate) Then
    nRow = r.Row
    found = True
    Exit For
End If
'Other code

Re: แสดงข้อมูลใน Listbox

Posted: Wed Nov 22, 2017 8:46 am
by Benmore
snasui wrote::D ตัวอย่างการค้นหา 2 เงื่อนไขพร้อมกันครับ

Code: Select all

'Other code
If Right(r.Value, 3) = Right(txtsearch1.Value, 3) And r.Offset(0, 4).Value2 = CLng(chkDate) Then
    nRow = r.Row
    found = True
    Exit For
End If
'Other code
ตรงนี้ทำได้แล้วขอบคุณมากค่ะ รบกวนดูตรง OptionButton ให้หน่อยค่ะ
เช่น ถ้าต้องการค้นหาข้อมูลแล้วมีสถานะว่ามารับแล้ว ให้ OptionButton "มารับแล้ว" ถูกติ๊กค่ะ

Code: Select all

Private Sub btsearch1_Click()
On Error Resume Next
If txtsearch1.Value = "" Or cmday.Value = "" Or cmmonth.Value = "" Or cmyear.Value = "" Then
                MsgBox "¡ÃسÒãÊè¢éÍÁÙÅãËé¤Ãº"
                Combobox1.Value = ""
        Exit Sub
    End If
   Dim found As Boolean
   Dim txt As String
   Dim r As Range
    Dim chkDate As Date
    Dim nRow As String
    chkDate = DateSerial(cmyear, cmmonth.ListIndex + 1, cmday)
    Sheet9.Activate
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
    If Right(r.Value, 3) = Right(txtsearch1.Value, 3) Or r.Offset(0, 0).Value2 = CLng(chkDate) Then
        nRow = r.Row
        found = True
        Exit For
    End If
    Next r
    If found Then
        If Not IsNumeric(VBA.Right(txtsearch1.Text, 3)) Then
            MsgBox "¡ÃسÒãÊè¢éÍÁÙÅà»ç¹µÑÇàÅ¢"
            Exit Sub
  TextBox7.Value = ""
    TextBox8.Value = ""
    TextBox9.Value = ""
    TextBox10.Value = ""
      TextBox11.Value = ""
         TextBox16.Value = ""
            TextBox17.Value = ""
        TextBox12.Value = ""
          If OptionButton9.Value = True Then
    ElseIf OptionButton10.Value = True Then
        ElseIf OptionButton11.Value = True Then
        OptionButton11.Value = TextBox13.Value
    End If
    'MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
 TextBox7.Value = Cells(nRow, 1)
TextBox8.Value = Cells(nRow, 2)
    TextBox9.Value = Cells(nRow, 3)
    TextBox10.Value = Cells(nRow, 4)
      TextBox11.Value = Cells(nRow, 6)
      TextBox16.Value = Cells(nRow, 7)
      TextBox17.Value = Cells(nRow, 8)
        TextBox12.Value = Cells(nRow, 9)
           If OptionButton9.Value = True Then
           OptionButton9.Value = Cells(nRow, 10)
    ElseIf OptionButton10.Value = True Then
    OptionButton10.Value = Cells(nRow, 10)
        ElseIf OptionButton11.Value = True Then
        TextBox13.Value = Cells(nRow, 10)
    End If
     Exit Sub
     Else
       MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
    Sheet1.Activate
End Sub

Re: แสดงข้อมูลใน Listbox

Posted: Fri Nov 24, 2017 8:48 am
by Benmore
:?: :?: :?: :shock: :shock: :shock:

Re: แสดงข้อมูลใน Listbox

Posted: Sun Nov 26, 2017 10:42 am
by snasui
Benmore wrote: :?: :?: :?: :shock: :shock: :shock:
:D ฟอรัมนี้ไม่อนุญาตให้มีการดันกระทู้ด้วยการโพสต์โดยไม่มีคำถามหรือข้อความอื่นใดครับ

หากตอบไม่ทันใจหรือช้าไปบ้างเป็นเพราะผู้ตอบอาจจะติดภารกิจ

ในส่วนที่ถามมาเกี่ยวกับการทำเครื่องหมายที่ ObtionButton9 กรณีการ Search เป็นมีสถานะว่า "มารับแล้ว" ไม่ทราบว่าบรรทัดใดใน Code ที่เขียนให้แสดงผลแล้วไม่ได้ตามที่ต้องการ แจ้งมาด้วย หากยังไม่เขียนให้เขียนมาก่อน จะได้ตอบต่อไปจากนั้นครับ

Re: แสดงข้อมูลใน Listbox

Posted: Mon Nov 27, 2017 12:08 am
by Benmore
ตรงนี้ทำได้แล้ว ขอบคุณค่ะ
ขอสอบถามเพิ่มเติมค่ะ
:ard:
:arrow: Userform10 :arl:
ถ้าต้องการค้นหาข้อมูลด้วยรหัสพนักงานกับเดือน ต้องเพิ่มโค้ดตรงไหนค่ะ
เช่น ถ้าต้องการค้าหาข้อมูลการเบิกชุดของพนักงานรหัส 009 ในเดือน November ให้แสดงข้อมูลการเบิกชุดทั้งหมดในชีทการเบิกของพนักงานรหัส 009 ในเดือน November ค่ะ

Code: Select all

Private Sub CommandButton5_Click()
 If txtsearch.Value = "" Or Commonth.Value = "" Then
                MsgBox "¡ÃسÒàÅ×Í¡¢éÍÁÙÅ¡è͹"
        Exit Sub
        End If
 Dim found As Boolean
   Dim txt As String
   Dim r As Range
    On Error Resume Next
    Dim nRow As String
    For Each r In Sheet9.Columns(1).SpecialCells(xlCellTypeConstants)
    Sheet9.Activate
        If Right(r.Value, 3) = Right(txtsearch.Text, 3) Then
            nRow = r.Row
            found = True
            Exit For
        End If
    Next r
    If found Then
        If Not IsNumeric(VBA.Right(txtsearch.Text, 3)) Then
            MsgBox "¡ÃسÒãÊè¢éÍÁÙÅà»ç¹µÑÇàÅ¢"
            Exit Sub
        End If
        If Err.Number = 91 Then
        TextBox1.RowSource = "txtsearch.Text & combobox1.value"
    End If
   txt = "Emp_ID : " & Cells(nRow, 1) & vbCrLf & _
    "Name : " & Cells(nRow, 2) & vbCrLf & _
    "Section : " & Cells(nRow, 3) & vbCrLf & _
    "Uniform_No : " & Cells(nRow, 4) & vbCrLf & vbCrLf & _
    "Date : " & Cells(nRow, 5) & vbCrLf & _
    "Discription : " & Cells(nRow, 6) & vbCrLf & _
    "Reason : " & Cells(nRow, 7) & vbCrLf & _
     "Status : " & Cells(nRow, 8)
    TextBox1.Value = txt
    Exit Sub
    Else
        MsgBox "äÁèÁÕ¢éÍÁÙÅ"
    End If
End Sub

Re: แสดงข้อมูลใน Listbox

Posted: Wed Nov 29, 2017 6:37 am
by snasui
:D ตัวอย่าง Code ครับ

Code: Select all

'Other code
If Right(r.Value, 3) = Right(txtsearch.Text, 3) And _
    Commonth.Text = Application.Text(r.Offset(0, 4).Value, "[$- ]mmmm") Then
    nRow = r.Row
    found = True
    Exit For
End If
'Other code