Help
Can someone help me with this code please:
Private Sub cmdImport_Click()
Dim db As Database
Dim rec As Recordset
Dim sqlstr As String
sqlstr = "tblAttendance"
Set db = CurrentDb
Set rec = db.OpenRecordset(sqlstr)
rec.Index = "StudentID"
rec.Seek = Me.StudentID
If rec.RecordCount > 0 Then
MsgBox ("Exists")
ElseIf Me.StartDate > Me.CurrentWk + 7 Then
MsgBox ("The student has not started the project yet.")
ElseIf Me.EndDate < Me.CurrentWk + 7 Then
MsgBox ("The student has finished the project.")
Else
DoCmd.OpenQuery ("qryImport")
End If
End Sub
The code is attached to a button called import. This is on a from linked to a table called tblStudents, which shows all students in the database.
What i want to do is open a form called frmAttendance which is based on tblAttendance. An import button is on this form which in turn opens the form above. i want to be able to import a student from tblStudents, but only if they do not exist in the tblAttendance.
Just can't get it.
Can someone help me with this code please:
Private Sub cmdImport_Click()
Dim db As Database
Dim rec As Recordset
Dim sqlstr As String
sqlstr = "tblAttendance"
Set db = CurrentDb
Set rec = db.OpenRecordset(sqlstr)
rec.Index = "StudentID"
rec.Seek = Me.StudentID
If rec.RecordCount > 0 Then
MsgBox ("Exists")
ElseIf Me.StartDate > Me.CurrentWk + 7 Then
MsgBox ("The student has not started the project yet.")
ElseIf Me.EndDate < Me.CurrentWk + 7 Then
MsgBox ("The student has finished the project.")
Else
DoCmd.OpenQuery ("qryImport")
End If
End Sub
The code is attached to a button called import. This is on a from linked to a table called tblStudents, which shows all students in the database.
What i want to do is open a form called frmAttendance which is based on tblAttendance. An import button is on this form which in turn opens the form above. i want to be able to import a student from tblStudents, but only if they do not exist in the tblAttendance.
Just can't get it.