Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Posts
    1

    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.
    Name: text
    Age - text
    Address: 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.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    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
    Code:
    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
    In the called form
    Code:
    Private Sub Form_Load()
    
    If Not IsNull(Me.OpenArgs) Then
      DoCmd.GoToRecord , , acNewRec
      Me.[Hospital Number] = Me.OpenArgs
    End If
    
    End Sub
    Note that I've enclosed Hospital Number in Square Brackets, in the code. This is necessary when using a control name that has spaces in it. This practice is really frowned on. You'd be much better off using a name like HospitalNumber or Hospital_Number.

    Linq ;0)>
    Last edited by Missinglinq; 04-24-11 at 14: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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •