Page 1 of 2

ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Thu May 23, 2019 10:31 pm
by yodpao.b
ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ
ต้องการให้ ในช่อง เป้าหมายและผลประหยัด update ข้อมูลลงช่องที่ถูกต้องครับ
เช่น
เป้าหมาย 2561 ลงในคอลัม I
เป้าหมาย 2562 ลงในคอลัม j
เป้าหมาย 2563 ลงในคอลัม k
ทั้งนี้ ต้องเลื่อน SpinButton ไปยัง พศ 2566 และแก้ไขตัวเลยดังรูป ที่ 1
ทำตามลูกสอนแดงและแก้ตามสีเหลืองครับ
แล้วจึง กดปุ่ม update
Capture3.JPG
ผลที่ได้ในรูปด้านล่าง
Capture2.JPG
จริงๆแล้วในช่องคอลัม I J K ต้องไม่เปลี่ยนแปลง
แต่จะไปเปลี่ยนในช่อง L M N ครับดังรูปด้านล่าง
Capture1.JPG
ไฟล์ส่งไม่ได้ครับ
เดียวล่งใหใหม่

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Thu May 23, 2019 10:31 pm
by yodpao.b
ส่งไฟล

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Thu May 23, 2019 10:38 pm
by yodpao.b
code ที่ใช้

Code: Select all

Private Sub CommandButton2_Click()
'»ØèÁ Update

If Me.cmbslno.Value = "" Then
MsgBox "ID No Can Not be Blank!!!", vbExclamation, "SL No"
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim i As Integer
i = 0
Do While Not IsEmpty(Sheet15.Cells(4 + i, 1).Value)
    If Sheet15.Cells(4 + i, 1).Value = cmbslno.Text Then
          Sheet15.Cells(4 + i, 8).Value = Noname.Text & " " & Textname.Text
          Sheet15.Cells(4 + i, 9).Value = TextBox01.Text
          Sheet15.Cells(4 + i, 10).Value = TextBox02.Text
          Sheet15.Cells(4 + i, 11).Value = TextBox03.Text
          Sheet15.Cells(4 + i, 15).Value = TextBox11.Text
          Sheet15.Cells(4 + i, 16).Value = TextBox12.Text
          Sheet15.Cells(4 + i, 17).Value = TextBox13.Text
          Sheet15.Cells(4 + i, 22).Value = ComboBox21.Text
          Sheet15.Cells(4 + i, 23).Value = ComboBox22.Text
          Sheet15.Cells(4 + i, 24).Value = ComboBox23.Text
                MsgBox "¨Ñ´à¡çºÅ§ã¹°Ò¹¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ"
        Exit Do
    End If
    i = i + 1
Loop

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim j, already As Integer
ListBox01.Clear
j = 0
Do While Not IsEmpty(Sheet15.Cells(4 + j, 8).Value)
    already = 0
    If Sheet15.Cells(4 + j, 3).Value = ComboBox02.Value Then
            If Sheet15.Cells(4 + j, 2).Value = ComboBox01.Value Then
                    ListBox01.AddItem Sheet15.Cells(4 + j, 8).Value
            End If
    End If
    j = j + 1
Loop

Call Blank

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ComboBox21.Clear
ComboBox22.Clear
ComboBox23.Clear
Call open_comboBox2

End Sub
code ที่ทำงานให้ใส่ในช่อง

Code: Select all

Dim i As Integer
i = 0
Do While Not IsEmpty(Sheet15.Cells(4 + i, 1).Value)
    If Sheet15.Cells(4 + i, 1).Value = cmbslno.Text Then
          Sheet15.Cells(4 + i, 8).Value = Noname.Text & " " & Textname.Text
          Sheet15.Cells(4 + i, 9).Value = TextBox01.Text
          Sheet15.Cells(4 + i, 10).Value = TextBox02.Text
          Sheet15.Cells(4 + i, 11).Value = TextBox03.Text
          Sheet15.Cells(4 + i, 15).Value = TextBox11.Text
          Sheet15.Cells(4 + i, 16).Value = TextBox12.Text
          Sheet15.Cells(4 + i, 17).Value = TextBox13.Text
          Sheet15.Cells(4 + i, 22).Value = ComboBox21.Text
          Sheet15.Cells(4 + i, 23).Value = ComboBox22.Text
          Sheet15.Cells(4 + i, 24).Value = ComboBox23.Text
                MsgBox "¨Ñ´à¡çºÅ§ã¹°Ò¹¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ"
        Exit Do
    End If
    i = i + 1
Loop
ผมไม่เข้าว่าจะทำอย่างไรให้ textbox รู้ว่าควรใส่ตาม พศ.ครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Fri May 24, 2019 6:16 am
by snasui
:D ช่วยยกตัวอย่างข้อมูลที่ต้องกรอกใน UserForm, Object ที่ผู้ใช้จะต้องคลิก และผลลัพธ์ที่ต้องการ จะได้สะดวกกับผู้ตอบในการทำตามขั้นตอนและสังเกตการทำงานของ Code ครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Fri May 24, 2019 9:22 am
by yodpao.b
ยกตัวอย่างข้อมูลที่ต้องกรอกใน UserForm, Object ที่ผู้ใช้จะต้องคลิก
1.JPG
ดูที่ sheet data เพื่อดูการเปลี่ยนแปลงดังรูปบนตามสีเหลือง
เปิด UserForm1
2.JPG
เลือกObjectดังนี้ดังรูปบน
3.JPG
สังเกตุ , แล้วเลือกลูกศรจนเห็นปี 2566

ขอขึ้นโพสตใหม่ครับ add รูปไมได้

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Fri May 24, 2019 9:34 am
by yodpao.b
4.JPG
แก้ไขดังรูปด้านบน
คลิกปุ่ม update และ cancel
จนขั้นตอนการเลือก
ผลที่ได้ดังรูปด้านล่าง ซึ่งผิด
5.JPG
ตัดเลข 10 ควรขึ้นในปี 2564 , 2565 , 2566
และในช่อง 2561 2562 2563 ควรเป็นค่าเดิมตามรูปด้านบนสุด

รูปแแบบหรือความต้องการที่ถูกต้องตามรูปด้านล่าง
6.JPG

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Fri May 24, 2019 10:38 am
by yodpao.b
4.JPG
แก้ไขดังรูปด้านบน
คลิกปุ่ม update และ cancel
จนขั้นตอนการเลือก
ผลที่ได้ดังรูปด้านล่าง ซึ่งผิด
5.JPG

ตัดเลข 10 ควรขึ้นในปี 2564 , 2565 , 2566
และในช่อง 2561 2562 2563 ควรเป็นค่าเดิมตามรูปด้านบนสุด

รูปแแบบหรือความต้องการที่ถูกต้องตามรูปด้านล่าง
6.JPG

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Fri May 24, 2019 10:39 am
by yodpao.b
#6 Post by yodpao.b » 24 May 2019 09:34
โฟตที่ 6 เรียงรูปผิดครับขอโทษ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Fri May 24, 2019 10:43 pm
by snasui
:D ตัวอย่างการปรับ Code ครับ

ประกาศตัวแปร x เพิ่มด้านบนสุดจะได้เป็น

Code: Select all

Dim currow As Integer
Dim x As Integer
ปรับ Code ที่ Procedure pinButton1_Change จะได้เป็น

Code: Select all

Public Sub SpinButton1_Change()
'     curyear = SpinButton.Value
    x = Me.SpinButton1.Value - Me.SpinButton1.Min
     Label101.Caption = "พ.ศ." & SpinButton1.Value - 1
     Label102.Caption = "พ.ศ." & SpinButton1.Value
     Label103.Caption = "พ.ศ." & SpinButton1.Value + 1
    'Other code
ปรับ Code ที่ CommandButton2_Click จะได้เป็น

Code: Select all

Private Sub CommandButton2_Click()
'»ØèÁ Update

If Me.cmbslno.Value = "" Then
MsgBox "ID No Can Not be Blank!!!", vbExclamation, "SL No"
Exit Sub
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim i As Integer
i = 0
Do While Not IsEmpty(Sheet15.Cells(4 + i, 1).Value)
    If Sheet15.Cells(4 + i, 1).Value = cmbslno.Text Then
          Sheet15.Cells(4 + i, 8).Value = Noname.Text & " " & Textname.Text
          Sheet15.Cells(4 + i, 9 + x).Value = TextBox01.Text
          Sheet15.Cells(4 + i, 10 + x).Value = TextBox02.Text
          Sheet15.Cells(4 + i, 11 + x).Value = TextBox03.Text
          'Other code

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 1:30 pm
by yodpao.b
ขอบคุณมากครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 3:55 pm
by yodpao.b
ในกรณีที่เราเลือกชื่อใน List box
แล้วปรับ SpinButton ไปยัง ปี 2566

กลับไปเลือกรายการอื่นใน List box ใหม่อีกครั้งหนึ่ง
จะเห็นว่า SpinButton ไม่กลับมาอยู่ในสถานเดิม ตือ 2561
ต้องการให้ SpinButton กลับมาอยู่ในสถานะเดิม ตือ 2561
ผมใช้ SpinButton1.Default มัน bug

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 4:21 pm
by snasui
:D จะให้มันกลับไปเหมือนเดิมก็ต้องทำการ Reset มันใหม่ด้วย Event ของการคลิกรายการใน ListBox ครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 4:49 pm
by yodpao.b
ใช้ code อะไรครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 4:52 pm
by snasui
:lol: ผมไม่ตอบเป็น Code อยู่แล้วครับ ยกเว้นเขียนมาแล้วให้ช่วยดูให้ครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 5:41 pm
by yodpao.b
เปิด UserForm1
ทำดตามรูปดังนี้
Capture1.JPG
Capture2.JPG
Capture3.JPG

Code: Select all

Private Sub ListBox01_Click()

    Dim i As Integer
    i = 0
    Do While Not IsEmpty(Sheet15.Cells(4 + i, 8).Value)
        If Sheet15.Cells(4 + i, 8).Value = ListBox01.Text Then
            cmbslno2.Text = Sheet15.Cells(4 + i, 4).Value
'            SpinButton1.Min = "2562"
'            goal(SpinButton1.Value - 2562) = 0
            Label101.Caption = "¾.È." & 2561
            Label102.Caption = "¾.È." & 2562
            Label103.Caption = "¾.È." & 2563
            Label111.Caption = "¾.È." & 2561
            Label112.Caption = "¾.È." & 2562
            Label113.Caption = "¾.È." & 2563
        
            Exit Do
        End If
    i = i + 1
    Loop
    
End Sub

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 5:45 pm
by yodpao.b
ไฟล

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 5:52 pm
by snasui
:D ตัวอย่างการปรับ Code ครับ

Code: Select all

Private Sub ListBox01_Click()
    Dim i As Integer
    i = 0
    SpinButton1.Value = SpinButton1.Min
    Label101.Caption = "¾.È." & SpinButton1.Min - 1
    Label102.Caption = "¾.È." & 2562
    Label103.Caption = "¾.È." & SpinButton1.Min + 1
    Label111.Caption = "¾.È." & SpinButton1.Min - 1
    Label112.Caption = "¾.È." & 2562
    Label113.Caption = "¾.È." & SpinButton1.Min + 1
    'Other code
    

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sat May 25, 2019 6:39 pm
by yodpao.b
ขอบคุณมากครับ
ได้ตามต้องการครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sun May 26, 2019 12:35 am
by yodpao.b
ต้องการ
ก่อนที่ทำการ Add . ให้ Noname.text(1.1.1) ตรวจสอบ ค่าในคอลัม F
ถ้าครงกันให้ไม่ add ถ้าไม่ตรงกันถึงaddได้
Capture4.JPG

Code: Select all

Private Sub CommandButton4_Click()
'ปุ่ม Add
On Error Resume Next
Dim i As Integer
Dim j As Integer
i = 0

If Me.cmbslno.Value = "" Or Me.Noname.Value = "" Or Me.Textname.Value = "" Then
MsgBox "ID Number Record Can Not be Blank!!!", vbExclamation, "ID Number"
     Exit Sub
End If
      
cmbslno1.Text = "E-" & Application.Text(Application.Max([max_no]) + 1, "0000")
cmbslno2.Text = Application.Max([max_no]) + 1
cmbslno.Text = cmbslno1.Text
      
Do While Not IsEmpty(Sheet15.Cells(3 + i, 6).Value)
    If Sheet15.Cells(3 + i, 6).Value <> Noname.Text Then
        Do
            If IsEmpty(Sheet15.Cells(3 + i, 1).Value) = False Then
                        i = i + 1
            End If
                Loop Until IsEmpty(Sheet15.Cells(3 + i, 1).Value) = True
                Sheet15.Cells(3 + i, 1).Value = cmbslno.Text
                Sheet15.Cells(3 + i, 2).Value = ComboBox01.Text
                Sheet15.Cells(3 + i, 3).Value = ComboBox02.Text
                Sheet15.Cells(3 + i, 4).Value = cmbslno2.Text
                Sheet15.Cells(3 + i, 5).Value = "-"
                Sheet15.Cells(3 + i, 6).Value = Noname.Text
                Sheet15.Cells(3 + i, 7).Value = Textname.Text
                Sheet15.Cells(3 + i, 8).Value = Noname.Text & " " & Textname.Text
                    For j = 0 To 5
                        Sheet15.Cells(3 + i, 9 + j).Value = goal(j)
                        Sheet15.Cells(3 + i, 15 + j).Value = actual(j)
                    Next j
                Sheet15.Cells(3 + i, 22).Value = ComboBox21.Text
                Sheet15.Cells(3 + i, 23).Value = ComboBox22.Text
                Sheet15.Cells(3 + i, 24).Value = ComboBox23.Text
                Call Blank
                Call ClearListBox01
                    MsgBox "จัดเก็บลงในฐานข้อมูลเรียบร้อยแล้ว"
            End If
    i = i + 1
Loop
    
'    CommandButton4.Enabled = False
'    CommandButton3.Enabled = True
'    CommandButton2.Enabled = True
'    CommandButton5.Enabled = True

End Sub
code นี้ทำงาน ไม่ตรวจสอบคาครับ

Re: ใช้ SpinButton ผล update ช้อมูลลงผิดช่องครับ

Posted: Sun May 26, 2019 6:52 am
by snasui
:D ตัวอย่าง Code ครับ

Code: Select all

Private Sub CommandButton4_Click()
    'ปุ่ม Add
    On Error Resume Next
    Dim i As Integer
    i = 0
    With Worksheets("Data")
        If Application.CountIf(.Range("f4", .Range("f" & .Rows.Count).End(xlUp)), _
            Me.Noname.Text) > 0 Then
            MsgBox "Please check sub item.", vbInformation
        End If
    End With
'Other code