(with VB5)
I am trying to make an application that can add, edit and delete data to, in and from a database, but I am having problems with the my adding and editing subroutines
here is my adding code:
Sub subAdd()
strWhere = ""
strSubject = "SELECT Subject.SubjectID FROM Subject WHERE Subject.SubjectName = '" & Me.dbcSubject & "';"
Set Recordset = Database.OpenRecordset(strSubject)
strSubjectID = Recordset!SubjectID
strTeacher = "SELECT Teacher.TeacherID FROM Teacher WHERE Teacher.TeacherName = '" & Me.dbcTeacher & "';"
Set Recordset = Database.OpenRecordset(strTeacher)
strTeacherID = Recordset!TeacherID
strAdd = "INSERT INTO Work(Dateset, Datedue, SubjectID, TeacherID, YearGroup, Details, Additionalinfo)"
If Not (txtDateSet.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtDateSet.Text
End If
If Not (txtDateDue.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtDateDue.Text
End If
If Not (Me.dbcSubject = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & strSubjectID
End If
If Not (Me.dbcTeacher = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & strTeacherID
End If
If Not (Me.cmbYear = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & Me.cmbYear
End If
If Not (txtHomework.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtHomework.Text
End If
If Not (txtAdditional.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtAdditional.Text
End If
strAdd = strAdd & strWhere & ""
Set Recordset = Database.OpenRecordset("SELECT * FROM Work"
Recordset.Execute strAdd
End Sub
Private Sub Form_Load()
standrews = "E:\Chris\College\Computing\standrews.mdb"
Set Workspace = DBEngine.Workspaces(0)
Set Database = Workspace.OpenDatabase(standrews)
End Sub
There seems to be a problem with the "Recordset.Execute strAdd" line
I am trying to make an application that can add, edit and delete data to, in and from a database, but I am having problems with the my adding and editing subroutines
here is my adding code:
Sub subAdd()
strWhere = ""
strSubject = "SELECT Subject.SubjectID FROM Subject WHERE Subject.SubjectName = '" & Me.dbcSubject & "';"
Set Recordset = Database.OpenRecordset(strSubject)
strSubjectID = Recordset!SubjectID
strTeacher = "SELECT Teacher.TeacherID FROM Teacher WHERE Teacher.TeacherName = '" & Me.dbcTeacher & "';"
Set Recordset = Database.OpenRecordset(strTeacher)
strTeacherID = Recordset!TeacherID
strAdd = "INSERT INTO Work(Dateset, Datedue, SubjectID, TeacherID, YearGroup, Details, Additionalinfo)"
If Not (txtDateSet.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtDateSet.Text
End If
If Not (txtDateDue.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtDateDue.Text
End If
If Not (Me.dbcSubject = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & strSubjectID
End If
If Not (Me.dbcTeacher = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & strTeacherID
End If
If Not (Me.cmbYear = vbNullString) Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & Me.cmbYear
End If
If Not (txtHomework.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtHomework.Text
End If
If Not (txtAdditional.Text = "" Then
If Len(strWhere) > 0 Then
strWhere = strWhere & ", "
Else
strWhere = strWhere & " VALUES ("
End If
strWhere = strWhere & txtAdditional.Text
End If
strAdd = strAdd & strWhere & ""
Set Recordset = Database.OpenRecordset("SELECT * FROM Work"
Recordset.Execute strAdd
End Sub
Private Sub Form_Load()
standrews = "E:\Chris\College\Computing\standrews.mdb"
Set Workspace = DBEngine.Workspaces(0)
Set Database = Workspace.OpenDatabase(standrews)
End Sub
There seems to be a problem with the "Recordset.Execute strAdd" line