ขอสอบถาม กรณี ไม่ได้กรอกข้อมูล TextBox ใน form
Posted: Sat Feb 12, 2022 12:51 pm
ขอสอบถาม กรณี ไม่ได้กรอกข้อมูล TextBox ใน form ค่ะ
ตอนนี้สร้างฟอร์มสำหรับให้ user กรอกข้อมูล user แต่ละคน จะมีข้อมูลไม่ครบทุก cell ในฟอร์มนั้น
เลยอยากจะให้ cell ใดก็ตาม ที่ user ไม่ได้กรอกข้อมูล ให้ค่าใน cell นั้นเป็น 0.00 หลังกดปุ่ม เพิ่มข้อมูล ค่ะ
แล้วค่า 0.00 นั้น จะไป insert ในตารางที่กำหนด ทำให้ตารางจะไม่มี cell ใดที่เป็นค่าว่างค่ะ
เขียนโค้ดไว้แบบนี้ค่ะ
Private Sub CommandButton1_Click()
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1) = ComboBox2.Text
Cells(r, 2) = ComboBox1.Text
Cells(r, 3) = TextBox1.Value
Cells(r, 4) = TextBox2.Value
Cells(r, 5) = TextBox3.Value
Cells(r, 6) = TextBox4.Value
Cells(r, 7) = TextBox5.Value
Cells(r, 8) = TextBox6.Value
Cells(r, 9) = TextBox7.Value
Cells(r, 11) = TextBox8.Value
Cells(r, 12) = TextBox9.Value
Cells(r, 13) = TextBox10.Value
Cells(r, 14) = TextBox11.Value
Cells(r, 15) = TextBox12.Value
Cells(r, 16) = TextBox13.Value
Cells(r, 17) = TextBox14.Value
Cells(r, 18) = TextBox15.Value
Cells(r, 19) = TextBox16.Value
Cells(r, 20) = TextBox17.Value
Cells(r, 21) = TextBox18.Value
Cells(r, 22) = TextBox19.Value
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
TextBox14.Value = ""
TextBox15.Value = ""
TextBox16.Value = ""
TextBox17.Value = ""
TextBox18.Value = ""
TextBox19.Value = ""
End Sub
Private Sub CommandButton2_Click()
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
TextBox14.Value = ""
TextBox15.Value = ""
TextBox16.Value = ""
TextBox17.Value = ""
TextBox18.Value = ""
TextBox19.Value = ""
End Sub
ตอนนี้สร้างฟอร์มสำหรับให้ user กรอกข้อมูล user แต่ละคน จะมีข้อมูลไม่ครบทุก cell ในฟอร์มนั้น
เลยอยากจะให้ cell ใดก็ตาม ที่ user ไม่ได้กรอกข้อมูล ให้ค่าใน cell นั้นเป็น 0.00 หลังกดปุ่ม เพิ่มข้อมูล ค่ะ
แล้วค่า 0.00 นั้น จะไป insert ในตารางที่กำหนด ทำให้ตารางจะไม่มี cell ใดที่เป็นค่าว่างค่ะ
เขียนโค้ดไว้แบบนี้ค่ะ
Private Sub CommandButton1_Click()
Do
r = r + 1
Loop Until Cells(r, 1) = ""
Cells(r, 1) = ComboBox2.Text
Cells(r, 2) = ComboBox1.Text
Cells(r, 3) = TextBox1.Value
Cells(r, 4) = TextBox2.Value
Cells(r, 5) = TextBox3.Value
Cells(r, 6) = TextBox4.Value
Cells(r, 7) = TextBox5.Value
Cells(r, 8) = TextBox6.Value
Cells(r, 9) = TextBox7.Value
Cells(r, 11) = TextBox8.Value
Cells(r, 12) = TextBox9.Value
Cells(r, 13) = TextBox10.Value
Cells(r, 14) = TextBox11.Value
Cells(r, 15) = TextBox12.Value
Cells(r, 16) = TextBox13.Value
Cells(r, 17) = TextBox14.Value
Cells(r, 18) = TextBox15.Value
Cells(r, 19) = TextBox16.Value
Cells(r, 20) = TextBox17.Value
Cells(r, 21) = TextBox18.Value
Cells(r, 22) = TextBox19.Value
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
TextBox14.Value = ""
TextBox15.Value = ""
TextBox16.Value = ""
TextBox17.Value = ""
TextBox18.Value = ""
TextBox19.Value = ""
End Sub
Private Sub CommandButton2_Click()
ComboBox1.Text = ""
ComboBox2.Text = ""
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
TextBox7.Value = ""
TextBox8.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
TextBox13.Value = ""
TextBox14.Value = ""
TextBox15.Value = ""
TextBox16.Value = ""
TextBox17.Value = ""
TextBox18.Value = ""
TextBox19.Value = ""
End Sub