Results 1 to 3 of 3
  1. #1
    Adam858 is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    4

    Unhappy Button not doing what I want it to!

    Hi All,

    I hope this is a fairly simple on for those of you in the know.. I have been struggling with this for a few days now and it is driving me mad!

    I have modified the northwind database to use it for my own system. I have an issue with the orders form. I have a new unbound text box control called [
    totalpaid]
    and I want to copy the data from the orders [total] field. The total field works out the total based on a sum in the footer of the order details subform.

    A command button with the onclick event code
    Me.totalpaid = Me.Total does the job perfectly, or so I thought!
    If the user updates an item in the subform, say [unitprice] for example, and leaves the cursor in the [unitprice] field without pressing tab or enter, then clicks straight on my command button (located on the main form) the main form doesn't get the total from the subform untill after the buttons code has copied the incorrect total from the [total] textbox control.

    So I thought it would just need to be refreshed, so I added "
    Me.refresh" to the buttons code, but it seems to run through the code in the wrong order and copies the data before the form refreshes!

    If I add a separate refresh button, click that and then click my copy button it works fine! But I need this to work from one button. So.. In a nutshell:

    Is there code that can make my button do the following

    1. Refresh the form

    2. Wait for the form to refresh

    3. Copy the value from the Total field to the Totalpaid field.

    _____________

    This works if I do it manually

    1. Click on the refresh button : Runs the code "Me.Refresh"

    2. Wait for a split second for the field to calculate.

    3. Click on the copy button : Runs the code "Me.totalpaid = Me.Total"

    but if I combine these two lines to make:
    Me.Refresh
    Me.totalpaid = Me.Total

    The form doesn't refresh till after the copy and the calculated field has the wrong value.
    Hope this makes sense guys, it really is driving me mad! I am very much a beginner in visual basic so I know I am probably just doing something stupid!

    Thanks in advance!



    Adam

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    You could try:
    Pareent.Refresh
    Or
    Parent.Recalc
    In the After Update event of the subform.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Adam858 is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    4
    Bob you are a genius! Thank you so much!

    Parent.Recalc in the after update event of the subform works perfectly! I've been battling with this for days, I knew it would be simple!

    Thanks again!

    All the best

    Adam

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

Similar Threads

  1. Replies: 0
    Last Post: 01-11-2012, 12:34 PM
  2. Replies: 10
    Last Post: 03-21-2011, 02:46 PM
  3. Replies: 1
    Last Post: 07-27-2010, 02:27 PM
  4. Replies: 6
    Last Post: 02-09-2010, 07:53 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