Results 1 to 6 of 6
  1. #1
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47

    Can I Force an OnCurrent Event?

    I'm using a form with a multiple record type subform.



    The heading of the subform contains a calculated field which is a percentage based upon a bound textbox value in the main form and one in the sub-form defined by a domain aggregate.

    The mainform also contains a button that opens a form that permits the User to update underlying fields in the table bound to the main form thus changing the value in the displayed % field identified above.

    Here's the problem ... when the fields in the update form's values are actually changed, upon close of the update form and return to the "calling" form the % field displays "#error" until the cursor is moved to another record in the sub-form then the field updates correctly.

    This suggests to me that the problem is that the updated record has never been written and therefore no OnCurrent event was triggered. How can I force a record update from the update form or is there a way to trigger the needed event upon return to the "calling" form after updating?

    Appreciate any assistance.

    bginhb

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by bginhb View Post

    This suggests to me that the problem is that the updated record has never been written and therefore no OnCurrent event was triggered.
    Slight incorrect analysis. The issue is that a form's records are not going to be updated just by another form's closing without doing a requery. Now, if you do a requery it will make it move to the beginning of the recordset which is likely not what you want. But you can try to call the form's On Current event by changing it from PRIVATE to PUBLIC and then in the closing form call that other form's On Current by using

    Forms!FormNameHere.OnCurrent

  3. #3
    hertfordkc is offline 18 year novice
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    481

    Have you tried I doing a subform requery immediately

    After the command that opens the update form?

  4. #4
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47

    Unfortunately I could not make either option work

    I tried both proposals but my results were unchanged.

    However I did find something else while experimenting ... I found that the problem would clear if I pressed F5 (refresh) twice after being returned to the primary form so I tried refreshing the form twice (from code) after closing the update form. That produced nothing either but suggests that the issue could be timing related.

    I'm still chasing a solution if there are other ideas I'm open.

    Thank you all,
    bginhb

  5. #5
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Instead of firing the On Current event then you should requery the form.

    Code:
    Dim rst As DAO.Recordset
    Dim lngID As Long
    
    Set rst = Forms!YourFormNameHere.RecordsetClone
    
    lngID = Forms!YourFormNameHere!IDFieldNameHere
    
    Forms!YourFormNameHere.Requery
    
    rst.FindFirst "[IDFieldNameHere]=" & lngID
    
    If rst.NoMatch Then
       MsgBox "Something went wrong.", vbExclamation, "Error - ID not found"
    Else
       Forms!YourFormNameHere.Bookmark = rst.Bookmark
    End If
    
    rst.Close
    Set rst = Nothing

  6. #6
    bginhb is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2011
    Location
    Huntington Beach, CA, USA
    Posts
    47

    That did the trick!

    Thanks once again Bob!

    The code did exactly what I needed and I believe that the application is now finished.

    Merry Xmas and Happy New Year.

    Bill

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

Similar Threads

  1. Delete button not working if there is code in onCurrent
    By accessnewb in forum Programming
    Replies: 4
    Last Post: 08-18-2011, 07:56 AM
  2. Unselect listview items in OnCurrent event
    By majq in forum Programming
    Replies: 0
    Last Post: 02-21-2011, 07:51 AM
  3. Oncurrent event too fast?
    By Neutrino in forum Forms
    Replies: 24
    Last Post: 01-08-2011, 02:48 PM
  4. Replies: 1
    Last Post: 12-05-2010, 02:34 AM
  5. OnCurrent error
    By dreamweaver547 in forum Security
    Replies: 1
    Last Post: 03-14-2010, 01:45 PM

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