Results 1 to 5 of 5
  1. #1
    betmck is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2014
    Posts
    3

    Can I use a macro to setvalues in a form with values from another form?

    I have a form call [Calculate Gross Pay] which record source is a query call [Gross pay].
    Also there is a form call [Payroll] which fields are bound to a table called [payroll].

    There are several records on the form[Calculate Gross Pay] and I need all records to be stored in the fields on the form [Payroll].
    When I run the macro to populate the records, only the first record is displayed on the [Payroll] form. How to repeat the macro until all records are copied?

    This is the Macro I am using:

    OpenQuery Gross Pay, Datasheet, Edit
    OpenForm Calculate Gross Pay, Datasheet, ,,Edit, Normal
    OpenForm Payroll, Datasheet, , , Edit, Normal


    SetValue [Forms]![Payroll]![PCdate], [Forms]![Calculate Gross Pay]![PayRegDate]
    SetValue [Forms]![Payroll]![PCEmp], [Forms]![Calculate Gross Pay]![PrEmpName]
    SetValue [Forms]![Payroll]![ PCNISB], [Forms]![Calculate Gross Pay]![ nisb]
    SetValue [Forms]![Payroll]![PCNISD], [Forms]![Calculate Gross Pay]![ NISD]
    SetValue [Forms]![Payroll]![PCpaye], [Forms]![Calculate Gross Pay]![ PAYE]
    GoToRecord Form, Calculate Gross Pay, Next,

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    First, is PrEmpName actually employee name or an ID? Should be saving an ID not name.

    Second, why is it necessary to save this data instead of just pull it in a query?

    Third, looping in a macro is next to impossible. Use VBA and recordset or an INSERT SELECT query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    betmck is offline Novice
    Windows XP Access 2007
    Join Date
    Sep 2014
    Posts
    3
    PrEmpName is employee name. I need to have year to date totals, so I thought saving the data would make it easier.

    Thanks, I will try the INSERT SELECT query

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    You could store those values in a temp table and or clean out and refresh as needed. Just an idea. You can convert the macro to vba but it does not always work as intended.

    Good Luck!

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What data are you trying to save? Each employees pay for entire pay period? Yes, certainly need to create records each pay period. INSERT SELECT to batch create records might accomplish.

    Why do you Gross Pay query open?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 19
    Last Post: 09-09-2014, 01:36 AM
  2. Replies: 5
    Last Post: 02-23-2014, 06:54 PM
  3. Form Button With Macro To Open Another Form
    By data808 in forum Macros
    Replies: 9
    Last Post: 01-27-2014, 11:54 AM
  4. Replies: 15
    Last Post: 03-07-2013, 09:39 PM
  5. Replies: 8
    Last Post: 08-02-2012, 08:48 AM

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