E
efandango
I want to copy a sequence of records from one form to another. At the moment
this is done via a command button with the code below. But having to click
the button each time is becoming painful on my fingers (there are '000s of
mouse clicks). So what I would like to do, is for each set of records, just
click the button once, and have the code work through the chosen set of
records, copying them one by one until there are no more records for that
chosen set.
I know this could easily be done with a query, but that would not suit the
purpose of this requirement, which is essentially for a form based teaching
aid. Whereby the student has to develop memory by sequentially revealing each
item in a list. (there are many lists). So I guess that I need a loop, but I
have no experience of loops and would appreciate some help/guidance on the
matter. Once I have the loop working, I want to then insert some code to
regulate the spead of the copy process, so that different students can go
slower or faster, depending on their abilities.
This is my code that works with the command button, which follows this
simple sequence.
1. Check for blank recipient.
2. copy from donor record into blank record
3. move to next record
4. repeat process until list exhausted.
Private Sub btn_Reveal_Run_Timer_Click()
On Error GoTo Proc_Err
DoCmd.SetWarnings False
'code below checks if the recipient record fields are blank, if so, then a
copy of the first record fields are transferred to the recipient form's
records.
If IsNull(Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint]) Then
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint] = Me.Run_waypoint
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Postcode] = Me.Postcode
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_Direction] = Me.Run_Direction
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[OrderSeq] = Me.OrderSeq
DoCmd.GoToRecord , , acNext
'If the recipient fields are not blank, then code below creates a new
record, and copies the next set of record fields.
ElseIf Not
IsNull(Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint]) Then
Forms![frm_Runs].[frm_Run_Reveal_Target].SetFocus
Forms![frm_Runs].[frm_Run_Reveal_Target].Form.[Run_waypoint].SetFocus
DoCmd.GoToRecord , , acNewRec
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint] = Me.Run_waypoint
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Postcode] = Me.Postcode
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_Direction] = Me.Run_Direction
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[OrderSeq] = Me.OrderSeq
'code below returns to the donor form and moves to the next record, ready
for the next button push, and so on...
Forms![frm_Runs].[frm_Run_Reveal_Selector].SetFocus
Forms![frm_Runs].[frm_Run_Reveal_Selector].Form.[Run_waypoint].SetFocus
DoCmd.GoToRecord , , acNext
End If
End
Proc_Err:
MsgBox "Run Complete"
DoCmd.SetWarnings True
End Sub
this is done via a command button with the code below. But having to click
the button each time is becoming painful on my fingers (there are '000s of
mouse clicks). So what I would like to do, is for each set of records, just
click the button once, and have the code work through the chosen set of
records, copying them one by one until there are no more records for that
chosen set.
I know this could easily be done with a query, but that would not suit the
purpose of this requirement, which is essentially for a form based teaching
aid. Whereby the student has to develop memory by sequentially revealing each
item in a list. (there are many lists). So I guess that I need a loop, but I
have no experience of loops and would appreciate some help/guidance on the
matter. Once I have the loop working, I want to then insert some code to
regulate the spead of the copy process, so that different students can go
slower or faster, depending on their abilities.
This is my code that works with the command button, which follows this
simple sequence.
1. Check for blank recipient.
2. copy from donor record into blank record
3. move to next record
4. repeat process until list exhausted.
Private Sub btn_Reveal_Run_Timer_Click()
On Error GoTo Proc_Err
DoCmd.SetWarnings False
'code below checks if the recipient record fields are blank, if so, then a
copy of the first record fields are transferred to the recipient form's
records.
If IsNull(Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint]) Then
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint] = Me.Run_waypoint
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Postcode] = Me.Postcode
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_Direction] = Me.Run_Direction
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[OrderSeq] = Me.OrderSeq
DoCmd.GoToRecord , , acNext
'If the recipient fields are not blank, then code below creates a new
record, and copies the next set of record fields.
ElseIf Not
IsNull(Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint]) Then
Forms![frm_Runs].[frm_Run_Reveal_Target].SetFocus
Forms![frm_Runs].[frm_Run_Reveal_Target].Form.[Run_waypoint].SetFocus
DoCmd.GoToRecord , , acNewRec
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_waypoint] = Me.Run_waypoint
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Postcode] = Me.Postcode
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[Run_Direction] = Me.Run_Direction
Forms.frm_Runs.[frm_Run_Reveal_Target].Form.[OrderSeq] = Me.OrderSeq
'code below returns to the donor form and moves to the next record, ready
for the next button push, and so on...
Forms![frm_Runs].[frm_Run_Reveal_Selector].SetFocus
Forms![frm_Runs].[frm_Run_Reveal_Selector].Form.[Run_waypoint].SetFocus
DoCmd.GoToRecord , , acNext
End If
End
Proc_Err:
MsgBox "Run Complete"
DoCmd.SetWarnings True
End Sub