G
Guest
I have a table with two fields: CourseNum (text) and time (text) in a table
called tblCourses. The course numbers are like this: 1001, 1002, 1003, 1101,
1102, 1103, 1201, 1202, 1203, etc.
The first three numbers denote the course and the last number the identifier
of that course. The first form I am using allows the user to select the
course number. After the user selects this I want the listbox (lstCourse) to
display only those courses from tblCourses that begin with that course number
and the time field for that record contains zero. . So if the user selected
100 from the first list box, the lstCourse listbox would display only 1001,
and 1003 if those were the only ones in the table with zeros in the second
field.
Using recordset, the following is what has been done. I error out on the
strFilter = "SELECT * FROM tblTimes WHERE CourseNum Like '" & strCriteria &
"'"
statement.
Private Sub Form_Load()
'load the list box with only the classes that have not already been
'modified with respect to there time field
Dim rst As ADODB.Recordset, strFilter As String, strCriteria As String
Dim rst2 As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
rst.Open "tblCourseCodes", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
rst.MoveFirst 'no need to check eof of rst,its a static list
Do While Not rst.EOF
strCriteria = rst.Fields("CourseCodes").Value & "*"
strFilter = "SELECT * FROM tblTimes WHERE CourseNum Like '" &
strCriteria & "'"
rst2.Open strFilter, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
If Not rst2.EOF Then
rst2.MoveFirst
End If
Do While Not rst2.EOF
If rst2.Fields("Time").Value = 0 Then
rst.Fields("DisplayCourse").Value = True
Exit Do
End If
rst2.MoveNext
Loop
rst.MoveNext
Loop
End Sub
Thank you for your help.
called tblCourses. The course numbers are like this: 1001, 1002, 1003, 1101,
1102, 1103, 1201, 1202, 1203, etc.
The first three numbers denote the course and the last number the identifier
of that course. The first form I am using allows the user to select the
course number. After the user selects this I want the listbox (lstCourse) to
display only those courses from tblCourses that begin with that course number
and the time field for that record contains zero. . So if the user selected
100 from the first list box, the lstCourse listbox would display only 1001,
and 1003 if those were the only ones in the table with zeros in the second
field.
Using recordset, the following is what has been done. I error out on the
strFilter = "SELECT * FROM tblTimes WHERE CourseNum Like '" & strCriteria &
"'"
statement.
Private Sub Form_Load()
'load the list box with only the classes that have not already been
'modified with respect to there time field
Dim rst As ADODB.Recordset, strFilter As String, strCriteria As String
Dim rst2 As ADODB.Recordset
Set rst = New ADODB.Recordset
Set rst2 = New ADODB.Recordset
rst.Open "tblCourseCodes", CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
rst.MoveFirst 'no need to check eof of rst,its a static list
Do While Not rst.EOF
strCriteria = rst.Fields("CourseCodes").Value & "*"
strFilter = "SELECT * FROM tblTimes WHERE CourseNum Like '" &
strCriteria & "'"
rst2.Open strFilter, CurrentProject.Connection, adOpenKeyset,
adLockOptimistic
If Not rst2.EOF Then
rst2.MoveFirst
End If
Do While Not rst2.EOF
If rst2.Fields("Time").Value = 0 Then
rst.Fields("DisplayCourse").Value = True
Exit Do
End If
rst2.MoveNext
Loop
rst.MoveNext
Loop
End Sub
Thank you for your help.