Page 1 of 1

VBA กรอกข้อมูลลงForm ให้ค้นหาข้อมูลก่อน

Posted: Thu Nov 28, 2019 3:15 pm
by Kartoonka
form stock - Copy.zip
(451.52 KiB) Downloaded 6 times
อยากเพิ่มเติมเวลากรอกข้อมูลถ้ามีข้อมูลอยู่แล้วให้ปรากฎขึ้นตามTextbox และขอแก้ไขได้โดยบันทึกลงที่เดิม ถ้าไม่มีข้อมูลในฐานข้อมูลถึงจะให้เพิ่มข้อมูลใหม่ลงไปได้


Private Sub CommandButton1_Click()
Dim A As Long
Sheets("database").Unprotect Password:="12345"
A = ThisWorkbook.Worksheets("Database").Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(A, 1) = TextBox1.Text
Cells(A, 2) = TextBox2.Text
Cells(A, 3) = TextBox3.Text
Cells(A, 4) = TextBox4.Text
Cells(A, 5) = TextBox5.Text
Cells(A, 6) = TextBox6.Text
Cells(A, 7) = TextBox7.Text
Cells(A, 8) = TextBox8.Text
Cells(A, 9) = TextBox9.Text
Cells(A, 10) = TextBox10.Text
Cells(A, 11) = TextBox11.Text
Cells(A, 12) = TextBox12.Text
Cells(A, 13) = TextBox13.Text
Cells(A, 14) = TextBox14.Text
Cells(A, 15) = TextBox15.Text
Cells(A, 16) = Now()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox13.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
Sheets("database").Protect Password:="12345"
End Sub

Private Sub CommandButton2_Click()

TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox13.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
End Sub

Re: VBA กรอกข้อมูลลงForm ให้ค้นหาข้อมูลก่อน

Posted: Thu Nov 28, 2019 7:04 pm
by snasui
:D กรุณาโพสต์ใหม่อีกครั้ง ดูวิธีการโพสต์ Code ตามกฎการใช้บอร์ดข้อ 5 ด้านบนครับ :roll: