กระทู้เก่าบอร์ด อ.สุภาพ ไชยา
310 2
URL.หัวข้อ /
URL
รบกวนช่วยดู Code หน่อยนะครับ
ปัญหาที่เกิดคือ ชื่ออาจาร์ยไม่ยอม Update เวลาเราเลือก รหัสอาจาร์ยใหม่นะครับ ขอบคุณครับที่เข้ามาช่วยตอบ
Option Compare Database
Option Explicit
Dim Mydb As Database
Dim MyRst As Recordset
Dim MyRsTeacher As Recordset
Dim MySql As String
Private Sub cbobinnumber_AfterUpdate()
MyRst.Seek "=", cbobinnumber.Value
MySql = "SELECT Teacher.TeacherID, ([forenames] & ' ' & [surname]) AS NameTeach FROM Teacher;"
Set MyRsTeacher = Mydb.OpenRecordset(MySql)
If MyRst.NoMatch = False Then
txtteachername.Value = MyRsTeacher.Fields("nameteach").Value
txtappnum.Value = MyRst.Fields("Appno").Value
txtExamDate.Value = MyRst.Fields("ExamDate").Value
Else
txtteachername.Value = Null
txtappnum.Value = Null
txtExamDate.Value = Null
End If
End Sub
Private Sub cbobinnumber_GotFocus()
Me.cbobinnumber.Requery
txtteachername.Requery
End Sub
Private Sub Cmdexit_Click()
DoCmd.Close
End Sub
Private Sub Form_Load()
Set Mydb = CurrentDb()
Set MyRst = Mydb.OpenRecordset("Registration")
Set MyRsTeacher = Mydb.OpenRecordset("Teacher")
MyRst.Index = "id"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Mydb.Close
End Sub
Option Compare Database
Option Explicit
Dim Mydb As Database
Dim MyRst As Recordset
Dim MyRsTeacher As Recordset
Dim MySql As String
Private Sub cbobinnumber_AfterUpdate()
MyRst.Seek "=", cbobinnumber.Value
MySql = "SELECT Teacher.TeacherID, ([forenames] & ' ' & [surname]) AS NameTeach FROM Teacher;"
Set MyRsTeacher = Mydb.OpenRecordset(MySql)
If MyRst.NoMatch = False Then
txtteachername.Value = MyRsTeacher.Fields("nameteach").Value
txtappnum.Value = MyRst.Fields("Appno").Value
txtExamDate.Value = MyRst.Fields("ExamDate").Value
Else
txtteachername.Value = Null
txtappnum.Value = Null
txtExamDate.Value = Null
End If
End Sub
Private Sub cbobinnumber_GotFocus()
Me.cbobinnumber.Requery
txtteachername.Requery
End Sub
Private Sub Cmdexit_Click()
DoCmd.Close
End Sub
Private Sub Form_Load()
Set Mydb = CurrentDb()
Set MyRst = Mydb.OpenRecordset("Registration")
Set MyRsTeacher = Mydb.OpenRecordset("Teacher")
MyRst.Index = "id"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Mydb.Close
End Sub
2 Reply in this Topic. Dispaly 1 pages and you are on page number 1
1 @R00139
เพิ่มเติมนะครับ
ใช้ 2 table
-Registratin
-Teacher
warut@eduprogress.com
2 @R00140
ลองเปลี่ยนโค้ดดังนี้ครับ
...
MySql = "SELECT Teacher.TeacherID, Teacher.forenames, Teacher.surname FROM Teacher;"
Set MyRsTeacher = Mydb.OpenRecordset(MySql)
If MyRst.NoMatch = False Then
txtteachername.Value = MyRsTeacher("forename") & " " & MyRsTeacher("surename")
...
Time: 0.1249s