Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data from a table

Status
Not open for further replies.

rann

Programmer
Sep 13, 2001
86
US
Hi,
I have a table as follows.

QuestionNum | Answer | NextQuestion
-------------------------------------------------------
1 | Yes | 2
1 | No | 3
2 | True | 4
2 | False | 4
3 | Male | 5
3 | Female | 6
5 | One | 6
5 | Two | 6
5 | Three | 7
6 | Yes | 7
6 | NO | 7
7 | Test1 | -
7 | Test2 | -

Given a QuestionNum i need to know all its NextQuestions.
(or all its lower tier questions).

I used a recursive function to solve the problem but it does not
work. Any code or alogorithms would be appreciated.

Any help would be helpfull,

Thanks in Advance,

Rann.

 
Could you Post what you have, we might be able to see where you went wrong. Many different ways of getting to what you want, depending on if it's in a recordset, array, etc.
 
Hi,
This is what i did.

Public Function LinkQuestions(intCurrent As Integer)
Dim strSQL As String
Dim rst As DAO.Recordset
Dim dat As DAO.Database
Dim intNextQuestion As Integer
Dim intIncrement As Integer
Dim blAdded As Boolean
strSQL = "Select QuestionNum,Answer,NextQuestion from Table where QuestionNum = " & intCurrent & ";"
Set dat = OpenDatabase("My datasource")
Set rst = dat.OpenRecordset(strSQL)

If rst.EOF = True Then
'No Linked Questions No recursion
rst.Close
Set rst = Nothing
dat.Close
Set dat = Nothing
Else
'This Question has Other Linked Questions

'Do While Not rstData.EOF
intNextQuestion = rst.Fields("NextQuestion")

'Loop
LinkQuestions(intNextQuestion)
'Since there is a next question call this function
'Recursively
rst.Close
Set rst = Nothing
dat.Close
Set dat = Nothing
End If
End Function

'The above code works partially.
'The problem is with do-loop i need to loop through all the
answers for each Question and find its next Question.

If all the Answers are linked to the same next question the
above Function Works great but not when all the Answers are linked to different NextQuestions.

Thanks in Advance,
Rann.
 
Do While Not rstData.EOF
intNextQuestion = rst.Fields("NextQuestion")
'Some code here
rst.MoveNext
Loop
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
What about something like
---------------------------------
Private sub ToBeOrNotToBe(intCurrent as integer)
Dim Rst as recortdset
Rst.open "Select NextQuestion from Table where QuestionNum = " & intCurrent & " group by NextQuestion", YourConnection
if Rst.eof and Rst.bof then
'no more questions....
else
While not Rst.eof
ToBeOrNotToBe Rst.Fields("NextQuestion")
Wend
end if
Rst.close
'....
end sub
---------------------------------
However, that would give you question 7 twice (if QuestionNum=5, you get 6 & 7 and 6 will also lead to 7) is that desireable?

In the 'real world' that would not happen (assuming that there is only one answer to each question).

What is the purpose of getting all possible 'question paths'?

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
HI,
It must have been the stress. The only Problem with my code is i forgot to add rst.movenext(Probably i was half a sleep) .Thanks CClint/Sunaj for your help.I really appreciate it.

Thanks,
Rann.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top