Results 1 to 12 of 12
  1. #1
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Requery method fails on subform (2002 SP2)

    I have a subform which contains the line items for an order. In that subform, if certain line items are deleted, then other optional line items also need to be deleted if they exist. The delete is being done using DAO that runs on the Form/Delete event, and works in a straightforward manner, except it leaves a line of "deleted" fields on the continuous subform. To try to get rid of this, I put in code at the end of the delete event saying <font face="Georgia"><font color=blue>Me.Requery</font color=blue></font face=georgia> and got the runtime error message 2118 - "You must save the current field before you run the Requery action." Specifying the full form and subform control name causes the same error message. I also tried using the DoCmd.Requery version and got a slightly different runtime error 2046 - "The command or action Requery isn't available now."

    I'm sure I've done this before on subforms and had it work - can anybody shed some light on this? I've even wondered if it is a timing issue or race condition.
    Wendell

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Requery method fails on subform (2002 SP2)

    "Optional line items"? Do they appear on the subform as well? That error message sounds strange, since you can't really save a field, only a record.
    Charlotte

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Requery method fails on subform (2002 SP2)

    Yes, the records are all stored in a single table and are displayed on the subform where the line items are being deleted. A messy situation that I don't like, but the client insisted. ARGH! Kevin suggested simply reseting the record source for the subform, which I haven't tried yet, but it seems like you should be able to do a Requery and that would be it.
    Wendell

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Requery method fails on subform (2002 SP2)

    So are you clearing fields in the same record or other records in the same table?? <img src=/S/confused.gif border=0 alt=confused width=15 height=20> The error message almost sounds like the AfterUpdate event of a control hasn't yet occurred.
    Charlotte

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Requery method fails on subform (2002 SP2)

    No clearing is going on - we actually run a SQL query to delete the records (usually one, but can be four or more in unusual cases) in the Form/Delete event before we actually let the delete of the primary record. I suppose it may have to do with the Delete event itself, and the fact that there is a pending delete which hasn't been cancelled, but the logic for deciding whether the delete should actually occur is in the delete event. I should think other people have encountered this issue before - and in thinking about it I think I've only done it with SQL Server backends, while this is an Access linked table.
    Wendell

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Requery method fails on subform (2002 SP2)

    Oh, I think I see. Your subform is bound to the table/query from which you're deleting records in code, right? In that case, you may need to either add a DoEvents before the requery or you may need to make sure the subform isn't dirty before you requery it. Have you tried a refresh? I usually turn the echo off until after the subform is updated in that case to avoid seeing the "deleted" values flash on the screen.
    Charlotte

  7. #7
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Requery method fails on subform (2002 SP2)

    I think you may have hit on it - I probably can't really do a requery until the Delete event has processed - the actual record or records that are left over with the "deleted" status are the related record. So the DoEvents command may well accomplish what I need and then let me do either a refresh or a requery. This whole thing is sort of based on a self-join which is a neat feature, but can also get you into trouble if you try to use referential integrity. I'll let you know how it turns out. Thanks very much.
    Wendell

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Requery method fails on subform (2002 SP2)

    Unfortunately, the DoEvents didn't seem to make anything happen. As it turns out the .Requery method causes both the BeforeUpdate and Current events to fire, and the error message looks to be coming from the Current event when all the error trapping is turned off - I do however get a different error - 3246 Reserved Error when the DoEvents happens just before the .Requery. Unfortunately, the .Refresh command doesn't make the "deleted" line go away. I'll try some other things and see if they fix it.
    Wendell

  9. #9
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Requery method fails on subform (2002 SP2)

    Are you doing deletes before the subform is doing it's deletes? Maybe there's a conflict here, with the subform records being in memory and you do your deletes from the table then the subform gets itself in a knot trying to access the tables deleted records.
    Just guessing here.
    Any chance of posting a cutdown DB for us mere mortals.

  10. #10
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Requery method fails on subform (2002 SP2)

    I think your are correct - at least it looks to be recursive when I try to step through the code, the Before Update and Current events are being triggered in the middle of the Delete event. The code for the delete event by itself is over 4 screens - it messes with backorders and a bunch of things. The code for just the subform is over 20 screens (at 1280x1024), and the main form is far more complex than the subform. Various developers have been working on this beast for over 10 years. The database (just the front-end is 42MB - the backends are about 300MB - there are 6 of them, one of which is 240MB so cutting it down to post it would be a major effort in and of itself.

    What we finally decided to do was to move all the code out of the delete event, and do everything in SQL from a command button. Basic testing of that approach indicates it should work. So I have a fair bit of rewriting in my tomorrow! <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15>
    Wendell

  11. #11
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Requery method fails on subform (2002 SP2)

    Keep us up to date on that one Wendell, I am interested to know how you solve this one.
    I feel for you for the amount of rewriting you have to do.

  12. #12
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Requery method fails on subform (2002 SP2)

    Just for the record, we moved all the code to the command button, wrote queries to delete first the dependent records, then the primary record, and removed all the code associated with the Delete event for the Form, and were able to do a simple Me.Refresh at the end of the command button routine. Everything now seems to work fine - the fundamental problem appeared to be some code related to the BeforeUpdate and Current events that were firing when the Refresh event was initiated. I suspect that it was related to that unique situation, and more normal situations would not exhibit the same behavior.
    Wendell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •