รบกวนผู้รู้ครับ
ผมขอสอบถามเกี่ยวกับ edit ผ่าน userForm
ผมค้นหาข้อมูล โดยใช้ เลขบัตรประชาชน แล้วคลิกที่ปุ่มค้นหาแล้วข้อมูลใน sheet "Febrile" มาแสดงใน userForm เมื่อมีการแก้ไขแล้วข้อมูลคลิกที่ปุ่มลัฃบันทึกข้อมูลกลับไปต่อที่ แถวสุดท้ายในsheet "Febrile"
สิ่งที่ต้องการ
1.ให้ข้อมูลที่แก้ไขแล้วไปทับแถวเดิม
ขอบคุณครับ
Code: Select all
Private Sub data_entry_btn_Click()
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("Febrile")
'find first empty row in database
irow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'Check for Id
If (Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
Exit Sub
End If
If Application.CountIf(Range("e:e"), TextBox4.Text) > 0 Then
MsgBox "ÁÕ¢éÍÁÙżÙé»èÇÂáÅéÇ"
Exit Sub
End If
'copy the data to the database
ws.Cells(irow, 1).Value = Me.TextBox1.Value
ws.Cells(irow, 2).Value = Me.ComboBox1.Value
ws.Cells(irow, 3).Value = Me.TextBox2.Value
ws.Cells(irow, 4).Value = Me.TextBox3.Value
ws.Cells(irow, 5).Value = Me.TextBox4.Value
ws.Cells(irow, 6).Value = Me.TextBox5.Value
ws.Cells(irow, 7).Value = Me.TextBox6.Value
ws.Cells(irow, 8).Value = Me.TextBox7.Value
ws.Cells(irow, 9).Value = Me.ComboBox2.Value
ws.Cells(irow, 10).Value = Me.ComboBox3.Value
ws.Cells(irow, 11).Value = Me.TextBox8.Value
ws.Cells(irow, 12).Value = Me.TextBox9.Value
ws.Cells(irow, 13).Value = Me.TextBox10.Value
ws.Cells(irow, 14).Value = Me.TextBox11.Value
ws.Cells(irow, 15).Value = Me.TextBox12.Value
ws.Cells(irow, 16).Value = Me.TextBox13.Value
ws.Cells(irow, 17).Value = Me.TextBox14.Value
ws.Cells(irow, 19).Value = Me.TextBox20.Value
ws.Cells(irow, 20).Value = Me.TextBox19.Value
ws.Cells(irow, 21).Value = Me.ComboBox4.Value
ws.Cells(irow, 22).Value = Me.ComboBox5.Value
ws.Cells(irow, 23).Value = Me.ComboBox6.Value
If OptionButton6.Value = True Then
ws.Cells(irow, 18).Value = OptionButton6.Caption
ElseIf OptionButton1.Value = True Then
ws.Cells(irow, 18).Value = OptionButton1.Caption
ElseIf OptionButton2.Value = True Then
ws.Cells(irow, 18).Value = OptionButton2.Caption
ElseIf OptionButton3.Value = True Then
ws.Cells(irow, 18).Value = OptionButton3.Caption
ElseIf OptionButton4.Value = True Then
ws.Cells(irow, 18).Value = OptionButton4.Caption
ElseIf OptionButton5.Value = True Then
ws.Cells(irow, 18).Value = OptionButton5.Caption
End If
'Clear the data
Me.TextBox1.Value = ""
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.ComboBox2.Value = ""
Me.ComboBox3.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.TextBox10.Value = ""
Me.TextBox11.Value = ""
Me.TextBox12.Value = ""
Me.TextBox13.Value = ""
Me.TextBox14.Value = ""
Me.TextBox20.Value = ""
Me.TextBox19.Value = ""
Me.ComboBox4.Value = ""
Me.ComboBox5.Value = ""
Me.ComboBox6.Value = ""
Me.TextBox1.SetFocus
If data_entry_btn Then
UserFrom.Hide
End If
MsgBox "à¾ÔèÁ¢éÍÁÙÅàÊÃç¨áÅéÇ"
End Sub