บอร์ดเรียนรู้ Access สำหรับคนไทย
Thai Access Webboard => ห้อง MS Access => ข้อความที่เริ่มโดย: kitisak ที่ 18 ก.ค. 62 , 18:16:11
-
จะซ่อนทั้งกลุ่ม โชว์ทั้งกลุ่ม แบบนี้ได้อย่างไร (คือมีวิธีเอา text box มาเป็นกลุ่มเดียวกัน แล้วซ่อนทั้งกลุ่ม)
เช่น
txtGroup1A0.visibel = false
txtGroup1A1.visibel = false
txtGroup1A2.visibel = false
txtGroup1A3.visibel = false
txtGroup1A4.visibel = false
txtGroup1A6.visibel = false
-
แบบที่ 1
ถ้าท่านกำหนด txtGroup1A0 1 2 3 4 5 6 .... / txtGroup1B 1 2 3 4 5 6 ...... / txtGroup2A 1 2 3 4 5 6 ... ไปแบบนี้ ใช้การกำหนดเงื่อนไขจากชื่อของตัว Control เอาก็ได้คับเช่น
Private Sub Command1_Click() 'เลือก Event ที่ต้องการครับ
Dim ctl As Control
For Each ctl In Me
If ctl.ControlType = acTextBox Then
If Left$(ctl.Name, 10) = "txtGroup1A" Then 'Left 10 เพราะต้องการเช็คตัวอักษรทางซ้าย 10 ตัวซึ่งเป็นชื่อที่เหมือนกันของกลุ่ม
ctl.Visible = False 'หรือ ctl.Visible = true หรือจะสร้างเงื่อนไขให้กลุ่มอื่นๆด้วยก็ได้เช่นกัน
End If
End If
Next ctl
End Sub
แบบที่ 2
อีกวิธีอาจจะง่ายกว่าคือการกำหนดชื่อของกลุ่มที่ Tag ของกล่องข้อความแล้วกำหนดเงือนไขการซ่อนและแสดง
ผมสมมุติ textbox 6 ตัวชื่อกลุ่ม Group1
(https://www.thai-access.com/tiupld/images/puv87g-416596.JPG)
Private Sub Command1_Click()
Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "Group1" Then
ctl.Visible = False
End If
Next ctl
End Sub