คือผมทำโปรแกรม library ของอุปกรณ์อิเล็กทรอนิกส์ คือทำให้ ค้นหาได้ ทำให้เพิ่ม ข้อมูลเข้าdbได้ ทำให้ลบได้
แต่ผมจะทำปุ่มแก้ไขใน db ควรเขียนออกมายังไงครับ นีึกภาพไม่ออกครับ
Private Sub DBList1_Click()
End Sub
Private Sub Command1_Click()
'On Error GoTo err:
If Text1.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ·Õè¨Ð¤é¹ËÒ", vbOKOnly + vbExclamation, "¤Óàµ×͹"
Text1.SetFocus
Exit Sub
End If
Adodc1.RecordSource = "select * from EcgData where Ecg like '%" + Text1 + "%'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount = 0 Then
MsgBox "äÁ辺¢éÍÁÙÅ"
Adodc1.RecordSource = "select * from EcgData"
Adodc1.Refresh
Exit Sub
End If
If Adodc1.Recordset.RecordCount = 1 Then
Text1.Text = Adodc1.Recordset.Fields(0)
Text2.Text = Adodc1.Recordset.Fields(1)
Text3.Text = Adodc1.Recordset.Fields(2)
Text4.Text = Adodc1.Recordset.Fields(3)
Exit Sub
Adodc1.RecordSource = "select * from EcgData"
Adodc1.Refresh
End If
Exit Sub
Text2.SetFocus
err:
MsgBox "ÁÕ¢éͼԴ¾ÅÒ´àÅ¢·Õè" & err.Number & " " & err.Description, vbInformation + vbOKOnly, "¢éͼԴ¾ÅÒ´"
Exit Sub
End Sub
Private Sub Command2_Click()
On Error GoTo EL:
Adodc1.RecordSource = "Select*from EcgData"
Adodc1.Refresh
Adodc1.Recordset.AddNew 'à¾ÔèÁ¢éÍÁÙÅ
Adodc1.Recordset.Fields(0) = Text2.Text '·Ó¡Òúѹ·Ö¡¢éÍÁÙŵÒÁÅӴѺ¢Í§ Field
Adodc1.Recordset.Fields(1) = Text3.Text
Adodc1.Recordset.Fields(2) = Text4.Text
Adodc1.Recordset.Fields(3) = Text5.Text
Adodc1.Recordset.Update '·Ó¡Òà ºÑ¹·Ö¡¢éÍÁÙÅ
MsgBox "ºÑ¹·Ö¡¢éÍÁÙÅàÊÃç¨àÃÕºÃéÍÂáÅéÇ" 'á¨é§¼Å¡Òúѹ·Ö¡¢éÍÁÙÅ
EL:
End Sub
Private Sub Command3_Click()
On Error GoTo err:
If MsgBox("¤Ø³µéͧ¡ÒÃź¢éÍÁÙÅËÃ×ÍäÁè?", vbInformation + vbYesNo, "Program") = vbYes Then
Adodc1.Recordset.Delete
MsgBox "ź¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ", vbOKOnly + vbInformation, "Program"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Adodc1.Refresh
End If
Exit Sub
err:
MsgBox err.Description
End Sub
Private Sub Command4_Click()
If Text2.Text = "" Then
MsgBox "â»Ã´¤ÅÔ¡àÅ×Í¡¢éÍÁÙÅ·Õèµéͧ¡ÒèÐá¡éä¢", vbOKOnly + vbExclamation, "Select Data"
End If
CheckEdit = True
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = True
Command5.Enabled = True
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
Text2.SetFocus
Adodc1.Recordset.Update '·Ó¡Òà ºÑ¹·Ö¡¢éÍÁÙÅ
MsgBox "·Ó¡Òà ºÑ¹·Ö¡¢éÍÁÙÅàÃÕºÃéÍÂáÅéÇ"
End If
EL:
End Sub
Private Sub Command6_Click()
On Error GoTo EL 'ËÒ¡ÁÕ¤ÇÒÁ¼Ô´¾ÅÒ´ãËéä»ÂѧºÃ÷Ѵ ·Õèª×èÍ EL (ÍÂÙè¡è͹ End Sub)
If Trim(Text2.Text) = "" Then Exit Sub '¶éÒäÁèÁÕ¡ÒáÃÍ¡¢éÍÁÙÅ㹪èͧ text1 ãËé¡àÅÔ¡¡Ò÷ӧҹ
Adodc1.RecordSource = "select * from EcgData" 'àÅ×Í¡ Fiels ·Ñé§ËÁ´ ¨Ò¡µÒÃÒ§ student
Adodc1.Refresh
Adodc1.Recordset.AddNew à¾ÔèÁ¢éÍÁÙÅ
Adodc1.Recordset.Fields(0) = Val(Text2.Text) '·Ó¡Òúѹ·Ö¡¢éÍÁÙŵÒÁÅӴѺ¢Í§ Field
Adodc1.Recordset.Fields(1) = Text3.Text
Adodc1.Recordset.Fields(2) = Text4.Text
Adodc1.Recordset.Fields(3) = Text5.Text
Adodc1.Recordset.Fields(4) = Text6.Text
Adodc1.Recordset.Fields(5) = Text7.Text
Adodc1.Recordset.Fields(6) = Text8.Text
Adodc1.Recordset.Update '·Ó¡Òà ºÑ¹·Ö¡¢éÍÁÙÅ
MsgBox "ºÑ¹·Ö¡¢éÍÁÙÅàÊÃç¨àÃÕºÃéÍÂáÅéÇ" 'á¨é§¼Å¡Òúѹ·Ö¡¢éÍÁÙÅ
EL:
End Sub
Private Sub Command7_Click()
End
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
Private Sub List1_Click()
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Text1.Text = "" Then
MsgBox "¡ÃسÒãÊèàºÍÃìÍØ»¡Ã³ìÏ"
Text1.SetFocus
Else
Command1.SetFocus
End If
End If
End Sub
ผมมทำปุ่ม command 1-7
1ค้นหา
2เพิ่ม
3ลบ
4แก้ไข
5ยกเลิก
6บันทึก
ึ7ออกโปรแกรม
ผมมีtextbox อยู่5
1ใช้ค้นหา
2-5 ใช้แอด ข้อมุลเข้า ดาต้ากริด
ผมมีดาต้ากริดอยู่ 1 ใช้แสดงผล
อยากสอบถามว่าผมควรเขียนโค๊ดยังไงดีจะใช้แก้ไข บันทึก เข้าดาต้ากริดครับ ช่วยแนะนำทีครับ เขียนให้ดูทีครับโค๊ดควรจะเป้นไงทั้งปุ่มแก้ไขและปุ่มบันทึก
และอีกอย่าง เราจะเขียนโค๊ดล๊อกได้ไหมว่า ไม่ให้ผู้ชายแก้ไขข้อมูลในดาต้ากลิตได้ แต่ให้แก้ไขในtextboxอย่างเดียว
ปล.สีแดงๆคือส่วนของปุ่ม แก้ไขครับ