I am trying to add data in a related table using the PK in the data in a form.
The form is based on a query selecting all Student records. Query not table because I wanted to show descriptions not numbers so have to have linked tables.
The code I have so far is:
Private Sub CmdAddCoursetoStudent_Click()
Dim dbsCollege As DAO.Database
Dim rstStudentAnnualcourses As DAO.Recordset
Dim intStuID As Integer
Dim strSQL As String
intStuID = Forms!frmStudentCourses!StudID
Set dbsCollege = CurrentDb
Set rstStudentAnnualcourses = dbsCollege.OpenRecordset("tblStudentsAnnualCourses")
strSQL = "INSERT INTO tblStudentsAnnualCourses([StuAnnCrsesStuID]) VALUES (intStuID)"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Me!ComboSelectCourse.Visible = True
Me!CmdSelectCourse.Visible = True
End Sub
and as is works but by using a prameter box to ask for the intStuID and then inserts the record. With single quotes around the intStuID I am not asked for the data and a record is inserted but no data in the appropriate field.
The making visible of controls at the end works and is for the next problem
What am I doing wrong?
Regards
Paul Sibson
Salisbury, UK
The form is based on a query selecting all Student records. Query not table because I wanted to show descriptions not numbers so have to have linked tables.
The code I have so far is:
Private Sub CmdAddCoursetoStudent_Click()
Dim dbsCollege As DAO.Database
Dim rstStudentAnnualcourses As DAO.Recordset
Dim intStuID As Integer
Dim strSQL As String
intStuID = Forms!frmStudentCourses!StudID
Set dbsCollege = CurrentDb
Set rstStudentAnnualcourses = dbsCollege.OpenRecordset("tblStudentsAnnualCourses")
strSQL = "INSERT INTO tblStudentsAnnualCourses([StuAnnCrsesStuID]) VALUES (intStuID)"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
Me!ComboSelectCourse.Visible = True
Me!CmdSelectCourse.Visible = True
End Sub
and as is works but by using a prameter box to ask for the intStuID and then inserts the record. With single quotes around the intStuID I am not asked for the data and a record is inserted but no data in the appropriate field.
The making visible of controls at the end works and is for the next problem
What am I doing wrong?

Regards
Paul Sibson
Salisbury, UK