Copy data from one record to a new record on a sub form

G

Guest

I have a form showing patient details with a sub form displaying all
associated referral details for the patient. One patient can have more than
one referral and I would like to be able to copy data from some of the fields
on the current referral when adding a new referral for the same patient. Is
this possible?
 
G

Guest

Yes, it is possible to do that. There are a number of ways, but one that is
fairly straight forward is to use the Tag property of the controls on the
form you want to replicate. I would suggest a command button on your form to
copy the record:

Private Sub cmdCopyRec_Click()
Dim varCtls As Variant
Dim lngCtr As Long

'Build an array of the controls to copy
varCtls = Array("txtPatientID","txtRefNo", "chkNotifed","chkRefDate")

'Loop throught the array and put the current value in the Tag

With Me
For lngCtr = 0 to UBound(varCtls)
.Controls(varCtls(lngCtr)).Tag = .Controls(varCtls(lngCtr)).Value
Next lngCtr
Docmd.GotoRecord ,,,acNewRec
For lngCtr = 0 to UBound(varCtls)
.Controls(varCtls(lngCtr)).Value = .Controls(varCtls(lngCtr)).Tag
Next lngCtr
End With
End Sub
 
G

Guest

Thank you for your help

I am fairly new to Access code and I am having some problem following your
suggestion could you please simplify. Also some of the fields on the referral
records are selected via a combo box will these fields still copy?
 
Joined
Jul 19, 2011
Messages
1
Reaction score
0
This is first time I am using an array. This code works great if the current record's fields have values. However, I get a type mismatch error when the field value is null. How do you account for null field values when using an array? Thank you very much.
 

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

Top