Your table design allows a student to be in 1 course only. Is this what you intended?
If a student enrolls/takes a second or third course, then your design requires you to replicate the row(s).
You may want to consider
tblStudentInfo --->tblStudentTakesCourse<-- tblCourse
Your set up allows the situation shown in the jpg-- probably not what you want.
Also during some review of altering the Report sort order at runtime, I found this link
http://allenbrowne.com/ser-33.html
While testing your code and checking the Report properties, I noticed that even when you clear the Sort order via your button, the Order By property of the Report remains. I set it specifically [Town],[Lastname] and it was not cleared via the Clear Sort Order button. I have attached a jpg showing the Report properties after doing the Clear Sort.
I created a module as an attempt to get
Code:
Function ShowTableFields() As String
'
'This proc was an attempt to get the field names of your table into an array.
'The array would contain the name to show in a combobox's Value list and the second
' index would be the position of the field in the table and I allowed a third index
'to be used fo you to indicate whether that field show be displayed or not
'
' So you could build your value list based on the array contents.
' If you don't want StudentId to be in the list, then mark it False
' I have put Name in place of fnm in the array
'My thinking was you could use the position of the field 0,1,2 etc to be used in
' an Order By statement.
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim x As Integer
Dim fldlist As String
Dim fldarray(11, 3) As Variant
Set db = CurrentDb
For Each tdf In db.TableDefs
If Left(tdf.Name, 4) <> "MSys" Then ' Don't enumerate the system tables
For x = 0 To tdf.Fields.Count - 1
'Debug.Print tdf.Name & "','" & tdf.Fields(x).Name
fldlist = fldlist & tdf.Fields(x).Name & ";"
fldarray(x, 1) = tdf.Fields(x).Name
'check for your fnm field
If tdf.Fields(x).Name = "fnm" Then fldarray(x, 1) = "Name"
fldarray(x, 2) = x
Debug.Print fldarray(x, 1) & " " & fldarray(x, 2) & " " & fldarray(x, 3)
Next x
End If
Next tdf
fldlist = Mid(fldlist, 1, Len(fldlist) - 1)
fldlist = Replace(fldlist, "fnm", "Name")
ShowTableFields = fldlist
Debug.Print ShowTableFields
End Function
The output from the debug.prints is
Code:
StudentID 0
Name 1
LastName 2
Address 3
Town 4
City 5
County 6
PostCode 7
Country 8
Telephone 9
CourseID 10
StudentID;Name;LastName;Address;Town;City;County;PostCode;Country;Telephone;CourseID
But as I got into this and saw that a Report has its own sorting and grouping that is applied before anything in your query, I think you should look at another approach. I am leaving the code here since it may be of some value (possibly) to you.
It seems a long and convoluted route to change the string that appears in a combo.
Perhaps someone else has a technique that can be applied.
Good luck with your project.