MarcMellor
Programmer
I want to select a group of records from an Access database according to certain criteria and then pick one at random and deposit the IDNumber (the Primary Key AutoNumber) in a variable to be used later. This is what I have so far:
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE Subject = 'Biology'"
Data1.refresh
QuestionsLimit = Data1.Recordset.RecordCount
Data1.Refresh
CursorNumber = Int(Rnd * QuestionsLimit) + 1
Data1.RecordSource Move CursorNumber
QuestionID = Text1.Text 'QuestionId is my variable into
'which I want to deposit the ID number and
'Text1.Text is linked to the Access IDNumber
'field
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE [IDNumber] = QuestionID"
Data1.Refresh
Unfortunately I always get a value of 2 for my QuestionID variable even though I get random numbers for CursorNumber. Depositing the IDNumber in a text box and then picking it up in a variable seems a bit cumbersum and may simply be too slow. Is there a way of doing it directly? I had a look at the GetRows method but I can't really understand my book well enough to get it to work. Any ideas?
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE Subject = 'Biology'"
Data1.refresh
QuestionsLimit = Data1.Recordset.RecordCount
Data1.Refresh
CursorNumber = Int(Rnd * QuestionsLimit) + 1
Data1.RecordSource Move CursorNumber
QuestionID = Text1.Text 'QuestionId is my variable into
'which I want to deposit the ID number and
'Text1.Text is linked to the Access IDNumber
'field
Data1.RecordSource = "SELECT * FROM QuestionsDatabase_
WHERE [IDNumber] = QuestionID"
Data1.Refresh
Unfortunately I always get a value of 2 for my QuestionID variable even though I get random numbers for CursorNumber. Depositing the IDNumber in a text box and then picking it up in a variable seems a bit cumbersum and may simply be too slow. Is there a way of doing it directly? I had a look at the GetRows method but I can't really understand my book well enough to get it to work. Any ideas?