Populating question listbox from option combo-boxes

W

Wullie

I am trying to set up a Knowledge database (not about access thankfully) and
at the moment have a form with 3 combo-boxes at the top of the page where a
person can narrow down the question (by school type, area type and category
type).

Once an option from these 3 has been selected, I want a list of questions
that fall into those categories to appear in a box below (first listbox).

After a question is selected from this, the relevant answer should then
appear in another box below this (currently a listbox, but maybe this should
be a text box).

Hope that makes sense.

At the moment, I have the following code behind the form, but when I make a
selection in the 3rd drop-down box, nothing populates in the question
list-box. Any help/advice would be greatly appreciated (more than happy to
start my coding from scratch again as well, if I have confused myself too
much before now).

Private Sub QuestionCategoryType_AfterUpdate()

Dim strQuestionSchoolType As String
Dim strQuestionAreaType As String
Dim strQuestionCategoryType As String
Dim strWhere As String

Const strcStub = "SELECT Question FROM QuestionResolution "
Const strcTail = " ORDER BY QuestionResolution.Question;"

If Not IsNull(Me.QuestionSchoolType) Then
strQuestionSchoolType = _
" AND (SchoolTypeID = """ & Me.QuestionSchoolType & """)"
End If
If Not IsNull(Me.QuestionAreaType) Then
strQuestionAreaType = _
" AND (AreaID = """ & Me.QuestionAreaType & """)"
End If
If Not IsNull(Me.QuestionCategoryType) Then
strQuestionCategoryType = _
" AND (CategoryID = """ & Me.QuestionCategoryType & """)"
End If

strWhere = _
strQuestionSchoolType & _
strQuestionAreaType & _
strQuestionCategoryType

If Len(strWhere) > 0 Then
' Replace leading " AND " with " WHERE ".
strWhere = " WHERE " & Mid$(strWhere, 6)
End If

' Me!SelectQuestion.RecordSource = strcStub & strWhere & strcTail
Me.SelectQuestion = strcStub & strWhere & strcTail

End Sub


Private Sub SelectQuestion_AfterUpdate()

Dim strAnswerSchoolType As String
Dim strAnswerAreaType As String
Dim strAnswerCategoryType As String
Dim strWhere As String

Const strcAnsStub = "SELECT Resolution FROM QuestionResolution "
Const strcAnsTail = " ORDER BY QuestionResolution.Resolution;"

If Not IsNull(Me.SelectQuestion) Then
strAnswerSchoolType = _
" WHERE (SchoolTypeID = """ & Me.SelectQuestion & """)"
End If

Me!AnswertoQuestion = strcAnsStub & strAnsSchoolType & strcAnsTail

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top