ardy
Registered User.
- Local time
- Today, 01:58
- Joined
- Sep 24, 2012
- Messages
- 98
Hello All….
I have two tables (Student, Guardians), well there are more but these two are involved in this SQL…. Student_ID is the linker between the two table (many to one – multiple guardians to a single student). I have a form(frm_Student_Add). My goal is once I add a student (capturing related information from the student) the Student_ID automatically gets added to the Guardian table. I have approached this from several ways none of which is working. So I figured I try the SQL statement. Here is what I am doing.
In the form(frm_Student_Add) I am doing a After Update code in one of the fields(Student_ID) using the code below. It should work but it doesn’t any idea why. I also am open to any suggestion as to approach ……
I have two tables (Student, Guardians), well there are more but these two are involved in this SQL…. Student_ID is the linker between the two table (many to one – multiple guardians to a single student). I have a form(frm_Student_Add). My goal is once I add a student (capturing related information from the student) the Student_ID automatically gets added to the Guardian table. I have approached this from several ways none of which is working. So I figured I try the SQL statement. Here is what I am doing.
In the form(frm_Student_Add) I am doing a After Update code in one of the fields(Student_ID) using the code below. It should work but it doesn’t any idea why. I also am open to any suggestion as to approach ……
Code:
Private Sub GUSD_Student_ID_AfterUpdate()
' Add student ID to Subform Student ID
Dim GUSD_ID As String
Dim SQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
GUSD_ID = Me.GUSD_Student_ID
MsgBox "The GUSD Student ID is " & GUSD_ID & vbNewLine _
& "Adding The Student ID to Parent Information" 'For testing
'----------------------------------------------------
On Error GoTo Err_GUSD_Student_ID_AfterUpdate
'Prevent user warnings
DoCmd.SetWarnings False
SQL = "INSERT INTO Guardians [(GUSD_Student_ID)] VALUES (""" & Me.GUSD_Student_ID & """)"
Debug.Print SQL
DoCmd.RunSQL SQL
'Allow user warnings
DoCmd.SetWarnings True
Exit_GUSD_Student_ID_AfterUpdate:
Exit Sub
Err_GUSD_Student_ID_AfterUpdate:
MsgBox Err.Description
Resume Exit_GUSD_Student_ID_AfterUpdate
EndSub