Results 1 to 14 of 14
  1. #1
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272

    Display record from a different form on a new opened form.

    Am trying to do something on access and am kind of stuck.



    I have two forms with names
    1. Salary
    2. Calculation

    The form salary has a field named “basic” which stores the basic salary of an individual in a linked table.

    I have created an after update event which opens the form “Calculation” (while the form “salary” remains opened) when the basic is entered.

    Calculation has two fields on it called “basic” and tax”
    Calculation is also linked to a separate table where the data is stored.

    What I want to do is, if I entered say 2000dollars in the basic, automatically the calculation form will open but I want the 2000dollars to be the amount appearing on the basic field of the calculation form.

    Currently, am able to open but only custom basic can be entered.
    Any help with this will be greatly appreciated

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Check out the 'openargs' parameter in docmd.openform

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I might hide the first form and just refer to the other form and its field, then don't show the 1st form until the 2nd is closed. That will prevent anyone from being able to alter the 1st form after the 2nd's field has been set. Since you'd have to set the form2 field value to open args (e.g. Me.myField = Me.OpenArgs) you could write
    Me.myField = Forms!1stForm.myField.
    Usually, many ways to do the same thing. My point is just that, and hiding the 1st form until it's safe to show it again (or just close it if that's what you want to do when 2nd form opens).
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Am kind of lost. Would be glad if I get a practical demonstration of it.

    Like an example to make it easier for my my understanding.

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    OK. In your after_update event in form Salary that opens form Calculation,

    Code:
    Docmd.openform "Calculation",,,,,,me.basic
    Aove me.basic refers to the control (textbox, combobox, etc) that holds basic in form Salary

    Then in form Calculation in the Form_Load event,

    Code:
    Me.basic = openargs
    This me.basic is the control (textbox) in form Calculation that you want to receive the openargs data.


    This is one method that allows you to pass information from one form while opening another form.

  6. #6
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by davegri View Post
    OK. In your after_update event in form Salary that opens form Calculation,

    Code:
    Docmd.openform "Calculation",,,,,,me.basic
    Aove me.basic refers to the control (textbox, combobox, etc) that holds basic in form Salary

    Then in form Calculation in the Form_Load event,

    Code:
    Me.basic = openargs
    This me.basic is the control (textbox) in form Calculation that you want to receive the openargs data.


    This is one method that allows you to pass information from one form while opening another form.
    I tried your code.
    And the basic was able to display on the calculation field as requested.

    But there was a little issue.
    I applied an after update event to the basic field of the calculation form.

    But when the basic appears on the calculation form, the after update event on the form doesn’t take effect unless I manually type the basic again before the after update event takes effect.

    Is there any fix to this?

  7. #7
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    But when the basic appears on the calculation form, the after update event on the form doesn’t take effect unless I manually type the basic again before the after update event takes effect.

    Is there any fix to this?
    Updating the basic field with code will not fire the after_update event, as you've discovered. Perhaps you can add a button to the form. The button on_click event can call the after_update event.

  8. #8
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by davegri View Post
    Updating the basic field with code will not fire the after_update event, as you've discovered. Perhaps you can add a button to the form. The button on_click event can call the after_update event.
    Have able to find a fix.
    I applied my code on the “On Got Focus” event and it worked

    Thanks to you all

  9. #9
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    I know this chapter is closed but I have another question that has a link with this post.

    Using the same form names, if I have two fields called start_date and end_date and I want to use the openargs to display the output on a report where both start date and end date will appear on the report, how will I do that?

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    I suggest you post a copy of your database(zip format) with only a few records to highlight your requirement and expected output.

    Where are if I have two fields called start_date and end_date?

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Easier to have the report pull those values from the form, I'd say.

    If you must use open args, pass a comma separated string (e.g. 1/1/2022,2/2/2022) and use the split function to separate them into values. If you try to pass the values as dates (#1/1/2022#) I think you'll find that the dates will be converted to a string anyway. So if you need date data type values, openArgs just makes this more difficult than it has to be.

    EDIT - best case is that the date fields are in the query that is (should be?) the recordsource for the report.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Interesting. Maybe I will have to think about another way out without openargs

  13. #13
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Quote Originally Posted by orange View Post
    I suggest you post a copy of your database(zip format) with only a few records to highlight your requirement and expected output.

    Where are if I have two fields called start_date and end_date?
    Will try and do that

  14. #14
    Emmanuel is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2020
    Posts
    272
    Have been able to find a fix. Thanks so much for your time

Please reply to this thread with any new information or opinions.

Similar Threads

  1. run vba once specific record is opened in form
    By mainerain in forum Programming
    Replies: 1
    Last Post: 07-08-2019, 02:12 PM
  2. Replies: 5
    Last Post: 09-17-2018, 11:06 AM
  3. Replies: 18
    Last Post: 08-02-2017, 12:56 PM
  4. Replies: 20
    Last Post: 06-22-2017, 10:36 AM
  5. Replies: 5
    Last Post: 10-18-2016, 06:00 AM

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
  •  
Other Forums: Microsoft Office Forums