Adding Data to a table using data on a form

pgsibson

Registered User.
Local time
Today, 14:54
Joined
Jan 24, 2008
Messages
44
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?:confused:

Regards
Paul Sibson
Salisbury, UK
 
Try

strSQL = "INSERT INTO tblStudentsAnnualCourses([StuAnnCrsesStuID]) VALUES (" & intStuID & ")"
 
Thanks Paul. Saved my life again
 
No problem. Don't forget to set warnings back to true, or use the more efficient

CurrentDb.Execute

which also doesn't throw the warnings.
 
my problem is similar. i have two tables linked to a form. the "address" field in the 'employees' table is linked to a hyperlink in the 'residences' table. However, in the form employees can be assigned a new address. i would like the links to appear when the newe address is given. i keep getting recordset is not updateable errors and i keep reading that this can't be done. is there a code that i can use that i can put in a button that will atuomatically look up the hyperlink in the 'residence' table based on what is displayed in the 'permanant address' field in the 'employee' table? that way i could eliminate the duality of the tables in the form and the recordset error as well.
 

Users who are viewing this thread

Back
Top Bottom