Hi JS/Nash:
This is an issue that I've run into several times. I've used the
recordsetclone successfully in the past, but a couple of weeks ago I was
working on a chemotherapy protocol form, which naturally would profit from a
carryover button for cycle 2, then 3, 4, etc. Only the dynaset method seemed
to work well, since I wanted the exact previous order- with the dynaset you
can order your records with the last one being a truely most recent record
posted, and likewise this goes for the previous record. Here's the actual
code from my database:
------------------------------------------------------------
Private Sub Command63_Click()
' this is sample code from Alberto Borges, MD
' (e-mail address removed)
On Error GoTo command63err
If MsgBox("Do you wish to overwrite any printed information? The date" &
Chr(13) & "will be the current date, but the Surface Area and Calvert" &
Chr(13) & "fields will reflect prior order's variable entries.", vbYesNo +
vbQuestion, "Copy new order information?") = vbNo Then
MsgBox "Event is cancelled.", vbExclamation
Else
[CDATE] = DATE
ii = Forms![*chemotherapy form]![EmbChemo1].Form![ORDER]
Set rst = Forms![*chemotherapy form]![EmbChemo1].Form.RecordsetClone
'Clone form's recordset
With rst
.FindFirst "[order] = " & ii
.MovePrevious
'Go back one record
'In case current record is 1st
If Not .EOF Then 'Grab specified field's value
oo = IIf(IsNull(![CHEMO]), " ", ![CHEMO])
kk = IIf(IsNull(![CHNM1]), " ", ![CHNM1])
ll = IIf(IsNull(![CHNM2]), " ", ![CHNM2])
DX = IIf(IsNull(![CHNM3]), " ", ![CHNM3])
rr = IIf(IsNull(![CHNM4]), " ", ![CHNM4])
XX = IIf(IsNull(![CHNM5]), " ", ![CHNM5])
yy = IIf(IsNull(![CHEM1]), 0, ![CHEM1])
zz = IIf(IsNull(![CHEM2]), 0, ![CHEM2])
.MoveNext
.Edit
![CHEMO] = oo
![CHNM1] = kk
![CHNM2] = ll
![CHNM3] = DX
![CHNM4] = rr
![CHNM5] = XX
![CHEM1] = yy
![CHEM2] = zz
.UPDATE
.MovePrevious
ww = IIf(IsNull(![CHEM3]), 0, ![CHEM3])
yy = IIf(IsNull(![CHEM4]), 0, ![CHEM4])
zz = IIf(IsNull(![CHEM5]), 0, ![CHEM5])
ii = IIf(IsNull(![CALC1]), 0, ![CALC1])
uu = IIf(IsNull(![CALC2]), 0, ![CALC2])
vv = IIf(IsNull(![CALC3]), 0, ![CALC3])
nn = IIf(IsNull(![CALC4]), 0, ![CALC4])
mm = IIf(IsNull(![CALC5]), 0, ![CALC5])
rr = Nz(![MGU1], ".")
ss = Nz(![MGU2], ".")
' now go back to your new record
.MoveNext
.Edit
![CHEM3] = ww
![CHEM4] = yy
![CHEM5] = zz
![CALC1] = ii
![CALC2] = uu
![CALC3] = vv
![CALC4] = nn
![CALC5] = mm
![MGU1] = rr
![MGU2] = ss
.UPDATE
.MovePrevious
ww = IIf(IsNull(![SA]), 0, ![SA])
yy = IIf(IsNull(![HT]), 0, ![HT])
zz = IIf(IsNull(![WT]), 0, ![WT])
ii = IIf(IsNull(![DOSERED]), 0, ![DOSERED])
uu = IIf(IsNull(![Calvert]), 0, ![Calvert])
vv = IIf(IsNull(![CalvertAdj]), 0, ![CalvertAdj])
.MoveNext
.Edit
![SA] = ww
![HT] = yy
![WT] = zz
![DOSERED] = ii
![Calvert] = uu
![CalvertAdj] = vv
.UPDATE
.MovePrevious
oo = Nz(![MGU3], ".")
rr = Nz(![MGU4], ".")
ss = Nz(![MGU5], ".")
tt = Nz(![INSTR1], ".")
XX = Nz(![INSTR2], ".")
DX = Nz(![INSTR3], ".")
CPT = Nz(![INSTR4], ".")
SQLStmt = Nz(![INSTR5], ".")
kk = Nz(![PRECHEMO], ".")
.MoveNext
.Edit
![MGU3] = oo
![MGU4] = rr
![MGU5] = ss
![INSTR1] = tt
![INSTR2] = XX
![INSTR3] = DX
![INSTR4] = CPT
![INSTR5] = SQLStmt
![PRECHEMO] = kk
.UPDATE
.MovePrevious
oo = Nz(![-2HR], ".")
rr = Nz(![-1HR], ".")
ss = Nz(![-1/2HR], ".")
DX = Nz(![FUTUREINST], ".")
CPT = Nz(![REFERENCE], ".")
.MoveNext
.Edit
![-2HR] = oo
![-1HR] = rr
![-1/2HR] = ss
![FUTUREINST] = DX
![REFERENCE] = CPT
.UPDATE
.Close
Me.Refresh
[CHEMO].SetFocus
End If
End With
End If
Exit Sub
command63err:
MsgBox "An error has occurred! If it persists, please notify software
administrator.", vbCritical
Exit Sub
End Sub
Regards,
Al