Populating a form from the previous record

petebevans

New member
Local time
Today, 11:00
Joined
Jun 9, 2008
Messages
9
I have designed a form that records pre-treatment activity for hospital patients. In some cases, a patient may require treatment on two different areas of their body but these would need to be added as separate records. Most of the fields in the two records would have the same value however so it would be nice to have a command button that saves the first record an pre-populates the next record with the previous values. Probably would not want to populate all the fields with the previous values so a way to selectively code the fields to populate would be useful. The primary key for the underlying table is an autonumber field so I would need the autonumber to increment as nornmal for the new record. I feel this should all be fairly simple to do but I can't get my brain around it. Any ideas? :rolleyes:
 
The first thing you would have to test for is that "does the patient have a previous visit to copy?" if not then nothing to do. If so, when the person clicks a button to add a new record then what you need to do is to code it accordingly

Bound Forms
Use the DoCmd to move to the last record in the list.

Copy the relevant fields to mem variables

Use the DoCmd to go to new record

Paste the relevant mem variables to the controls

David
 
Hi David,
Thank you for your very fast reply. I am afraid I am rather a rooky in the coding world so I am struggling with your reply. I understand 'DoCmd' but I haven't a clue what you mean by 'Copy the relevant fields to mem variables' and 'Paste the relevant mem variables to the controls'. Can you give an example of how you code these bits?
Yours hopefully,
Peter:confused:
 
Ok

When you are viewing the last record in the list for that patient they will be displayed in controls on your form, mostly textboxes. Let say the visit number is in a field called TxtVisitNo and its control source is VisitNo in your table.

You would declare variables in your forms declarations section namely

Dim IntVisitNo As Integer
Dim Something As Whatever
Etc


Then once you have issed your GoToLast command on the OnClick of your Add New Record Button you copy the contents of the controls to the variables. Go to a new record and set the default values to the controls accordingly.


GoToLast
IntVisitNo = Val(Me.TxtVisitNo)+1
GoToNew
Me.TxtVisitNo = IntVisitNo

Repeat for all appropriate controls and variables
 
Hi David,
I think I am with you now. I will give it a try. Thank you for your help.
Regards,
Peter:)
 

Users who are viewing this thread

Back
Top Bottom