我正在開發註冊系統。但我收到此錯誤:You tried to execute a query that does not include the specified expression..
訪問MS ACESS時出錯
我使用下面的代碼:
Private Function RefreshAdvisoryList()
Dim vRS As New ADODB.Recordset
Dim sSQL As String
'clear list
txtsection.Clear
'On Error GoTo ReleaseAndExit
sSQL = "SELECT tblSection.SectionID, tblSection.SectionTitle, tblAdviser.SchoolYear, tblDepartment.DepartmentTitle, tblYearLevel.YearLevelTitle, tblAdviser.TeacherID" & _
" FROM (tblDepartment INNER JOIN (tblYearLevel INNER JOIN tblSection ON tblYearLevel.YearLevelID = tblSection.YearLevelID) ON tblDepartment.DepartmentID = tblSection.DepartmentID) INNER JOIN tblAdviser ON (tblSection.SectionID = tblAdviser.SectionID) AND (tblDepartment.DepartmentID = tblAdviser.DepartmentID)" & _
" GROUP BY tblSection.SectionID, tblSection.SectionTitle, tblAdviser.SchoolYear, tblDepartment.DepartmentTitle, tblYearLevel.YearLevelTitle, tblAdviser.TeacherID" & _
" HAVING (((tblTeacher.TeacherID)='" & curTeacher.TeacherID & "') AND tblSection.SchoolYear='" & Me.txtSchoolYear.Text & "')" & _
" ORDER BY tblAdviser.SchoolYear DESC;"
If ConnectRS(con, vRS, sSQL) = False Then
'fatal
'temp
MsgBox "Unable to connect Teacher's Advisory Recordset.", vbCritical
'GoTo ReleaseAndExit
End If
If AnyRecordExisted(vRS) = True Then
While vRS.EOF = False
txtsection.AddItem vRS!SectionTitle
vRS.MoveNext
Wend
End If
'Exit Function
'ReleaseAndExit:
' Set vRS = Nothing
End Function
看看這張截圖:
我可以只更改HAVING子句中的2個字段以匹配SELECT字段嗎? –
這是我會嘗試的第一件事。當您在Access中嘗試將其作爲新查詢時會發生什麼? – HansUp
謝謝!其工作已經完成。我欠你一輛車。 :) –