04-24-11, 12:31 #1Registered User
- Join Date
- Apr 2011
Unanswered: want to autocopy one field value from one form to another
I have a form which enables me to enter a unique hospital inpatient number and other details of a patient to a table. After entering details, what I need is I should be able to go to another form to enter procedure details for this patient (for another table) and this form should open in add mode and automatically copy the unique in-patient number to the second form.
So I have a form with the following fields
Sl Number - Auto number
Hospital number - Text (as i dont need to do any calcs with this - each admission gets unique number, even for same patient.- Primary Key.
Age - text
I have inserted a hyperlink in this form which opens a macro which in turn opens another form in "Add" mode with following fields
procedure Sl Number - auto number
Hospital Number : which is going to be the same as in previous form and two tables into which these two forms enter data are joined by this field
Date of procedure: memo
date of discharge : date and time
What I need is after entering hosp number for a patient in first form, when I click the hyperlink for macro and open another empty form for procedure, I need hospital number to automatically be copied from first form
I'm relatively new to Access/VBA having just designed few simple databases to suit my needs.
04-24-11, 13:33 #2Moderator
Provided Answers: 19
- Join Date
- Jun 2005
- Richmond, Virginia USA
Like most experienced developers, here and elsewhere, I seldom use Macros as they're way too inflexible. But doing this with code, using the OpenArgs argument in the command to open the second form, is fairly simple.
In the calling form
Private Sub Go2SecondForm_Click() If Not IsNull(Me.[Hospital Number]) Then DoCmd.OpenForm "SecondForm", , , , acFormAdd, , Me.[Hospital Number] Else MsgBox "A Hospital Number Must Be Entered First!" End If End Sub
Private Sub Form_Load() If Not IsNull(Me.OpenArgs) Then DoCmd.GoToRecord , , acNewRec Me.[Hospital Number] = Me.OpenArgs End If End Sub
Last edited by Missinglinq; 04-24-11 at 13:49.Hope this helps!
The problem with making anything foolproof...is that fools are so darn ingenious!
All posts/responses based on Access 2003/2007