grundig1987
Registered User.
- Local time
- Today, 23:28
- Joined
- Dec 22, 2010
- Messages
- 31
Hi guys,
I have a multiple select list box (List112), in which students can choose up to 3 courses, out of a possible 8. I have a command button which validates the information using VBA to check that no 'bad' choices have been made. I then take the user to another access form, where they can choose 'backup' choices in case for whatever reason they are not able to get their first choice course(s).
The row source for List112 is a query for all semester 1 modules:
SELECT Courses.CourseName, Courses.CourseCredits
FROM Courses
WHERE (((Courses.CourseSemester)=1));
On the backup choices form (OptionDetailFormBackupChoices), I have 2 combo boxes (Combo58 & Combo60) which allow the student to choose a single 10 credit backup course, and a single 20 credit backup course. For example, Combo58:
SELECT Courses.CourseName, Courses.CourseCredits
FROM Courses
WHERE (((Courses.CourseCredits)=10) AND ((Courses.CourseSemester)=1));
This part of the code works fine, and it returns all Semester 1 courses with 10 credits. HOWEVER, I also want to remove the options that were already chosen in List112 on the previous form (OptionDetailForm2) - Below is the code I have used which concatenates all of the choices made in List112, and then splits them into an array called 'CoursesChosen' -
Private Sub List112_Click()
Dim ar() As String
Dim Count As Integer, i As Integer, j As Integer
Dim Msg As String
Dim CoursesChosen() As String
Count = 0
Msg = ""
For i = 0 To List112.ListCount - 1
'check if the row is selected and add to count
If List112.Selected(i) Then Count = Count + 1
Next i
'based on the above count declare the array
ReDim ar(Count)
j = 0
For i = 0 To List112.ListCount - 1
If List112.Selected(i) Then
'if selected then store the item from the
'first column in the array. change 1 to the
'respective column number
ar(j) = List112.Column(0, i)
j = j + 1
End If
Next i
'Check values stored in array
For i = 0 To Count - 1
MsgBox ar(i)
Msg = Msg & ar(i) & ","
Next i
CoursesChosen = Split(Msg, ",")
What I want to do is add this to the SQL, so something like the below:
SELECT Courses.CourseName, Courses.CourseCredits,Courses.CourseSemester
FROM Courses
WHERE (((Courses.CourseCredits)=10) AND (Courses.CourseName) NOT IN ("CoursesChosen") AND ((Courses.CourseSemester)=1));
I know the first thing you are probably thinking is that it won't return anything if I just put 'CoursesChosen' without an array figure, but even if I change this to 'CoursesChosen(0)' or 'CoursesChosen(1)' this does not make a difference.
I hope one of you can help with this. Everything is OK apart from recognition of the values selected in List112.
Thanks,
Mark
I have a multiple select list box (List112), in which students can choose up to 3 courses, out of a possible 8. I have a command button which validates the information using VBA to check that no 'bad' choices have been made. I then take the user to another access form, where they can choose 'backup' choices in case for whatever reason they are not able to get their first choice course(s).
The row source for List112 is a query for all semester 1 modules:
SELECT Courses.CourseName, Courses.CourseCredits
FROM Courses
WHERE (((Courses.CourseSemester)=1));
On the backup choices form (OptionDetailFormBackupChoices), I have 2 combo boxes (Combo58 & Combo60) which allow the student to choose a single 10 credit backup course, and a single 20 credit backup course. For example, Combo58:
SELECT Courses.CourseName, Courses.CourseCredits
FROM Courses
WHERE (((Courses.CourseCredits)=10) AND ((Courses.CourseSemester)=1));
This part of the code works fine, and it returns all Semester 1 courses with 10 credits. HOWEVER, I also want to remove the options that were already chosen in List112 on the previous form (OptionDetailForm2) - Below is the code I have used which concatenates all of the choices made in List112, and then splits them into an array called 'CoursesChosen' -
Private Sub List112_Click()
Dim ar() As String
Dim Count As Integer, i As Integer, j As Integer
Dim Msg As String
Dim CoursesChosen() As String
Count = 0
Msg = ""
For i = 0 To List112.ListCount - 1
'check if the row is selected and add to count
If List112.Selected(i) Then Count = Count + 1
Next i
'based on the above count declare the array
ReDim ar(Count)
j = 0
For i = 0 To List112.ListCount - 1
If List112.Selected(i) Then
'if selected then store the item from the
'first column in the array. change 1 to the
'respective column number
ar(j) = List112.Column(0, i)
j = j + 1
End If
Next i
'Check values stored in array
For i = 0 To Count - 1
MsgBox ar(i)
Msg = Msg & ar(i) & ","
Next i
CoursesChosen = Split(Msg, ",")
What I want to do is add this to the SQL, so something like the below:
SELECT Courses.CourseName, Courses.CourseCredits,Courses.CourseSemester
FROM Courses
WHERE (((Courses.CourseCredits)=10) AND (Courses.CourseName) NOT IN ("CoursesChosen") AND ((Courses.CourseSemester)=1));
I know the first thing you are probably thinking is that it won't return anything if I just put 'CoursesChosen' without an array figure, but even if I change this to 'CoursesChosen(0)' or 'CoursesChosen(1)' this does not make a difference.
I hope one of you can help with this. Everything is OK apart from recognition of the values selected in List112.
Thanks,
Mark