grundig1987
Registered User.
- Local time
- Today, 23:18
- Joined
- Dec 22, 2010
- Messages
- 31
Good Afternoon,
I will try and make this as clear as possible, and hope that someone on here can help me!
I have a table titled 'enrolments' - This table has 2 fields, StudentID, and CourseID. It is a one to many table so for example, one record could be:
StudentID B787878 CourseID BSB778
And another could be:
StudentID B787878 CourseID BNS885
In order for students to view the choices they have made, I have set up a form which has 6 text boxes (6 courses is the maximum a student can choose) - In each of these boxes I have code for Dlookup, as shown below:
Module_1 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_2 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_3 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_4 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_5 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_6 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Understandably each of these boxes only fills in with the first value in the table. Is there a way of using Dlookup to return all of the records that meet the criteria?
I have been searching endlessly for a piece of code to do this, and so far have only found the solution to be a recordset, with the code below:
dim db as database, rs as recordset
set db = currentdb()
set rs = db.openrecordset ("SELECT [TheField] FROM [TheTable] WHERE
TheWhereCondition")
with rs
while not .eof
debug.print ![the field]
.movenext
wend
end with
Using my information, I have put the code as below:
dim db as database, rs as recordset
set db = currentdb()
Set rs = db.OpenRecordset("SELECT [CourseID] FROM [Enrolments] WHERE [StudentID] = '" & Student_ID_4 & "'")
with rs
while not .eof
debug.print ![the field]
.movenext
wend
end with
When I run this code, it brings up 4 forms, and each of the 4 separate forms has the relevant StudentID, but each one has a different module. I am not sure why these are not on the same form? Can anybody help with this?
Thanks in advance,
Mark
I will try and make this as clear as possible, and hope that someone on here can help me!
I have a table titled 'enrolments' - This table has 2 fields, StudentID, and CourseID. It is a one to many table so for example, one record could be:
StudentID B787878 CourseID BSB778
And another could be:
StudentID B787878 CourseID BNS885
In order for students to view the choices they have made, I have set up a form which has 6 text boxes (6 courses is the maximum a student can choose) - In each of these boxes I have code for Dlookup, as shown below:
Module_1 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_2 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_3 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_4 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_5 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Module_6 = DLookup("[CourseID]", "Enrolments", "[StudentID] = '" & Student_ID_4 & "'")
Understandably each of these boxes only fills in with the first value in the table. Is there a way of using Dlookup to return all of the records that meet the criteria?
I have been searching endlessly for a piece of code to do this, and so far have only found the solution to be a recordset, with the code below:
dim db as database, rs as recordset
set db = currentdb()
set rs = db.openrecordset ("SELECT [TheField] FROM [TheTable] WHERE
TheWhereCondition")
with rs
while not .eof
debug.print ![the field]
.movenext
wend
end with
Using my information, I have put the code as below:
dim db as database, rs as recordset
set db = currentdb()
Set rs = db.OpenRecordset("SELECT [CourseID] FROM [Enrolments] WHERE [StudentID] = '" & Student_ID_4 & "'")
with rs
while not .eof
debug.print ![the field]
.movenext
wend
end with
When I run this code, it brings up 4 forms, and each of the 4 separate forms has the relevant StudentID, but each one has a different module. I am not sure why these are not on the same form? Can anybody help with this?
Thanks in advance,
Mark