Make a drawing via access using loop

Z

zionsaal

I have a table with one field in it and I wont to draw one record so
I created a form and I created a loop to go to the next record
randomly the whole table and then every second minute I stop the loop
and I
got the winner, means the record where the loop stop in it

but I don't have a way to stop the loop only by pressing ctrl break
I wont to code that when i will press any key it should stop running
the code and it should came up a MSG box with the name
any help please?
thanks


here is the code
Private Sub Command2_Click()
gggg:
DoCmd.GoToRecord , , acFirst
Do Until Me.NewRecord
DoCmd.GoToRecord
{here I wont to put: if key = enter then exit sub and do this and
this}
Loop
GoTo gggg
End Sub
 
G

Guest

Hi,
What is the point of looping through the records?
If you are after a particular record or group of records why not filter the
records. It would be far more efficient to do that than to sit through an
entire set of record waiting for it to pop up.

A bit more explanation on the purpose of the task will help in getting the
right code sorted out.
 
S

storrboy

If your intention is to pick a random record every two minutes like a
lottery, use the forms timer properties. Set timer interval to 120,000
(2 min) and in the OnTimer event, generate a random number between 1
and the number of records in the table/query. Move to that record
number. Place a button on the form that sets the Timer Interval to 0
when clicked - this stops the 'loop'. You could set this button to
restart the timer when clicked again.
 
Z

zionsaal

If your intention is to pick a random record every two minutes like a
lottery, use the forms timer properties. Set timer interval to 120,000
(2 min) and in the OnTimer event, generate a random number between 1
and the number of records in the table/query. Move to that record
number. Place a button on the form that sets the Timer Interval to 0
when clicked - this stops the 'loop'. You could set this button to
restart the timer when clicked again.

thanks
here is the code

Option Compare Database
Dim bol As Boolean


Private Sub Command2_Click()
bol = False
gggg:
DoCmd.GoToRecord , , acFirst
Do Until Me.NewRecord
DoCmd.GoToRecord
DoEvents
Loop
If bol = True Then Exit Sub
GoTo gggg
End Sub


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
bol = True
MsgBox Me.MasterID
End Sub
 
S

storrboy

thanks
here is the code

Option Compare Database
Dim bol As Boolean

Private Sub Command2_Click()
bol = False
gggg:
DoCmd.GoToRecord , , acFirst
Do Until Me.NewRecord
DoCmd.GoToRecord
DoEvents
Loop
If bol = True Then Exit Sub
GoTo gggg
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
bol = True
MsgBox Me.MasterID
End Sub


The code for what?
This isn't anything near what I suggested.
 

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

Similar Threads


Top