How have field on a form auto-populate with a data field from another form

I have a form that can be opened via a command button from four other forms.  When the 2nd form opens I want a date field to automatically populate from a date field that is in the 1st form.

But since this date field on the 2nd form can be opened from any one of 4 forms, I am not sure how to populate the date field,  Somehow the 2nd form has to know which of the 4 forms is open and use the date field from that form.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There are several solutions.  Here's two.

1. Before opening the pop up form, store the date in a memory variable.  That way the pop up form gets the date from a memory variable and doesn't care what form put it there.
2. Use the open args argument of the OpenForm Method to pass in the date.
Helen FeddemaCommented:
From the command button on each form, open the 2nd form, get the Date value from the calling form, using the syntax Me![txtDateField].Value, and write it to the appropriate Date field control on the other form, using the syntax Forms![frmSecondform]![txtDateField].Value.  You can do some error trapping if you wish.  Here is some sample code:
Private Sub cmdOpentargetform_Click()

   Dim dteStart As Date
   Dim frm As Access.Form
   If IsDate(Me![txtStartDate].Value) = True Then
      dteStart = Me![txtStartDate].Value
      DoCmd.OpenForm "frmTarget"
      Set frm = Forms![frmTarget]
      frm![txtStartDate] = dteStart
   End If
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.