The table under analysis is:
Question_Table(Course_Number, Question_ID, Question_Text, Answer_A, Answer_B, Answer_C, Answer_D, Answer_E, Answer_Weighting)
This is the question table based on a test application Im creating in VB6, simular to the MCSE or other multiple choice tests.
I want to generate an SQL/ or VB code to select 10 random questions and display each question when the cmdNextQuest cmd button is clicked. HERE IS THE CODE I HAVE WRITTEN SO FAR...it can display one record at the moment which consists of 1 question with 5 available multiple choice answers:
Private Sub Form_Load()
Dim db As DAO.Database
'This is the object that will hold the connection to the
'memory_training_database
'Dim n As Integer
Dim RS As Recordset
Dim RS1 As Recordset
'This is the object that will hold a set of records
'coming back from the database
Dim SQLString As String
'Dim SQLString_1 As String
'This is to temporarily hold the SQL string
Set db = OpenDatabase("e:\memory_training_database.mdb"
'This activates the database object, telling it
'to link to the memory_training_database.mdb.
'NOTE:you may have to change the path depending on where
'you have installed VB, and where your mbd is located
SQLString = "select * from Question_table where Course_id = '1'"
'SQL statement
Set RS = db.OpenRecordset(SQLString)
'Set RS1 = db.OpenRecordset(SQLString_1)
'This ties the recordset object with the database object
'You're telling it to set the recordset object to whatever
'the "db.OpenRecordset" function returns. And that function
'will return a set of records according to the SQL statement
'you pass it.
If RS.BOF = False And RS.EOF = False Then
lblTestQuestionnth.Caption = RS.Fields("question_text"
'n = 0
'Do While RS.EOF = False
lblTestAnswernth01.Caption = RS.Fields("Answer_A"
optAnswer1.Value = RS.Fields("answer_weighting"
'n = n + 1 - did not work properly but put here to show attempt
RS.MoveNext
'Loop - this did not work properly but put here to show attempt
lblTestAnswernth02.Caption = RS.Fields("Answer_B"
lblTestAnswernth03.Caption = RS.Fields("Answer_C"
lblTestAnswernth04.Caption = RS.Fields("Answer_D"
lblTestAnswernth05.Caption = RS.Fields("Answer_E"
'looks through the records to place in the text boxes
Else
MsgBox "no records found!"
End If
RS.Close
db.Close
End Sub
I know this is a long & tricky one, but any help is greatly appreciated!
Regards
Question_Table(Course_Number, Question_ID, Question_Text, Answer_A, Answer_B, Answer_C, Answer_D, Answer_E, Answer_Weighting)
This is the question table based on a test application Im creating in VB6, simular to the MCSE or other multiple choice tests.
I want to generate an SQL/ or VB code to select 10 random questions and display each question when the cmdNextQuest cmd button is clicked. HERE IS THE CODE I HAVE WRITTEN SO FAR...it can display one record at the moment which consists of 1 question with 5 available multiple choice answers:
Private Sub Form_Load()
Dim db As DAO.Database
'This is the object that will hold the connection to the
'memory_training_database
'Dim n As Integer
Dim RS As Recordset
Dim RS1 As Recordset
'This is the object that will hold a set of records
'coming back from the database
Dim SQLString As String
'Dim SQLString_1 As String
'This is to temporarily hold the SQL string
Set db = OpenDatabase("e:\memory_training_database.mdb"
'This activates the database object, telling it
'to link to the memory_training_database.mdb.
'NOTE:you may have to change the path depending on where
'you have installed VB, and where your mbd is located
SQLString = "select * from Question_table where Course_id = '1'"
'SQL statement
Set RS = db.OpenRecordset(SQLString)
'Set RS1 = db.OpenRecordset(SQLString_1)
'This ties the recordset object with the database object
'You're telling it to set the recordset object to whatever
'the "db.OpenRecordset" function returns. And that function
'will return a set of records according to the SQL statement
'you pass it.
If RS.BOF = False And RS.EOF = False Then
lblTestQuestionnth.Caption = RS.Fields("question_text"
'n = 0
'Do While RS.EOF = False
lblTestAnswernth01.Caption = RS.Fields("Answer_A"
optAnswer1.Value = RS.Fields("answer_weighting"
'n = n + 1 - did not work properly but put here to show attempt
RS.MoveNext
'Loop - this did not work properly but put here to show attempt
lblTestAnswernth02.Caption = RS.Fields("Answer_B"
lblTestAnswernth03.Caption = RS.Fields("Answer_C"
lblTestAnswernth04.Caption = RS.Fields("Answer_D"
lblTestAnswernth05.Caption = RS.Fields("Answer_E"
'looks through the records to place in the text boxes
Else
MsgBox "no records found!"
End If
RS.Close
db.Close
End Sub
I know this is a long & tricky one, but any help is greatly appreciated!
Regards