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

Posted on 2014-08-06
Last Modified: 2014-08-11
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.


Question by:SteveL13
    LVL 33

    Expert Comment

    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.
    LVL 31

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now