MarcMellor
Programmer
I need to download some questions from an Access database by selecting according to certain pre-chosen parameters and then pick one of these at random. QuestionID is the Primary Key AutoNumber in Access, RowNumber is the VB equivalent, QuestionLimit is the full count of questions under the selection, NumberOfSteps is my randomised number and Text1 is linked to the QuestionID field in Access.
This is my code:
Dim RowNumber As Long
Dim QuestionLimit As Integer
Dim NumberOfSteps As Integer
Randomize
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE Subject = 'Biology'
Data1.Refresh
QuestionLimit = Data1.Recordset.RecordCount
Dati.Refresh
NumberOfSteps = Int(Rnd * QuestionLimit) + 1
Data1.RecordSource.Move NumberOfSteps
RowNumber = Text1.Text
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE QuestionID = " & "'" & RowNumber & "'"
Data1.Refresh
This generates a "Run-time error 3464, Data type mis-match in criteria expression" and the last Data1 Refresh is highlighted by the debugger. I changed my Access QuestionID Field to Text (and Dim'ed in VB to suit) and it worked fine. But to work out code to replace the automatic action of AutoNumber in Access seems crazy. There must be a better way ........?
This is my code:
Dim RowNumber As Long
Dim QuestionLimit As Integer
Dim NumberOfSteps As Integer
Randomize
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE Subject = 'Biology'
Data1.Refresh
QuestionLimit = Data1.Recordset.RecordCount
Dati.Refresh
NumberOfSteps = Int(Rnd * QuestionLimit) + 1
Data1.RecordSource.Move NumberOfSteps
RowNumber = Text1.Text
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE QuestionID = " & "'" & RowNumber & "'"
Data1.Refresh
This generates a "Run-time error 3464, Data type mis-match in criteria expression" and the last Data1 Refresh is highlighted by the debugger. I changed my Access QuestionID Field to Text (and Dim'ed in VB to suit) and it worked fine. But to work out code to replace the automatic action of AutoNumber in Access seems crazy. There must be a better way ........?