Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    Thanks for looking into this. I have the Private Sub Form_Current and the Me.Dirty=False in another app and that does not affect Undo a new record at all.
    I even took those out of this and made no difference what so ever. I took out everything default, call to function, and it saves the record no matter what I do
    and like I said, i use the same code in a differet (older app) as I am trying to do this one better, and it will undo a record with no issues.
    I have stepped through as best as i can, still struggle with stepping through. Complies fine, well, i added some new forms back into this today and I have a
    couple of buttons missiing yet but that is on different forms and I will add them back in tomorrow when i revise them...

    Update: I was testing on my other app and when i hit Add, it goes to new record. With this app, When i hit Add, it goes to New and then a record number.


    Something is creating a record even before i do anything at all. I cant find it? Something is forcing this to a record immediately.....
    I found the issue and ' it out, see below and is in Form_Current. However now it goes to new record and will undo, i get an error of not updateable when i start
    to add the new record. Hit OK twice and will allow a record to be added? Please let me know why if you could.

    Code:
    'If IsActive = True Then
    'Me.AccountClosed = Null
    'Me.RecordLock = False
    'Else
    'Me.AccountClosed = Now()
    'Me.RecordLock = True
    'End If
    Get some rest, tomorrow another day
    Thanks
    Last edited by d9pierce1; 01-11-2022 at 01:41 AM. Reason: Added Update

  2. #17
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    like I said, i use the same code in a differet (older app) as I am trying to do this one better, and it will undo a record with no issues.
    Often claimed to be the same, seldom true. If it were true it should work?

    Not sure what else to tell you at this point. I step through and sometimes the UniqueID function is called sometimes not. No idea at the moment as to what's calling it, but when it runs it seems to add a record to tblAccount even though tblUniqueIDs has no relationships set. I cannot do a table refresh from the ribbon until the function is finished, but when I do, there's a new record even though there should not be. When it doesn't run, there's no record until you get to here in the current event
    Code:
    If IsActive = True Then
    Me.AccountClosed = Null
    Me.RecordLock = False
    Else
    Me.AccountClosed = Now()
    Me.RecordLock = True
    End If
    
        Me.Dirty = False
        Me.Refresh
    
    End Sub
    That makes sense to me, the function thing doesn't. How did you copy this file for posting? If from Windows Explorer, I suspect you might have copied a db that needs to be decompiled. I'm going to do that and see what happens about the function call. However, the red Me. lines make the form dirty and the bold saves the record as I said, so I cannot see how you can not save a record regardless, and then there is no Undo-ing. I can see that by refreshing the table as I step through.

    Other observations:
    When the function ran TxtRecordNo showed 46 of 45
    Select Case Me.cboAccountTypeID < Current event, case is 0 for new record. No block for that? Should have Case Else to notify you of the unexpected.
    Select Case Me.cboAccountTypeID < don't need IF block that follows, just the Me. lines. The Case statement is sort of an IF in itself.
    You could probably cut out a lot of your code. If a control is invisible, I don't think you have to worry about making it enabled since it can't take focus.

    EDIT - consider testing for both Me.NewRecord AND Me.Dirty then make False or not, as appropriate. Or don't make it False at any time. Is this necessary?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #18
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,778
    UPDATE
    I decompiled and recompiled - about 5 compile errors. IIRC, all to do with a missing function. Made no difference to what I observed earlier. The update function still runs when the Add button is clicked & no idea why as of yet.

    To make it easier to refresh the table and avoid refreshing the form as well I added
    Code:
        
    Me.Dirty = False
          DoCmd.SelectObject acTable, "tblAccount"
          DoCmd.Requery
          DoCmd.GoToRecord acDataTable, "tblAccount", acLast
        Me.Refresh
    
    End Sub
    I know I'm repeating myself, but after 3rd red line is executed, there is a record in the table, which is not there before the Me.Dirty = False.
    Conclusion is, the Dirty line is saving the record, which cannot then be undone. IMO your choices are
    - delete the record if the intention is to "cancel" its creation or
    - don't set form field values, then the new record will not be dirty thus will not save, or
    - ditch the Me.Dirty = False line or
    - use If Not Me.NewRecord And Me.Dirty Then Me.Dirty = False instead
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #19
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    thank you Micron,
    Appriciate it

  5. #20
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Hi Dave and Micron,
    Sorry for the late arrival, got curious about the error message .

    Dave, please review the attached file, I've made some changes (do a find in code for 'Vlad and you should find them all) and it seems to be working as expected now. The error message was caused by the fact that two textboxes bound to the calculated fields in the qryAccount (the form's recordsource) had a Default Value of 0; I removed that and the error went away. As for the error showing up twice - your form's Current event gets triggered twice, you might want to step through the code and optimize it a bit.

    Cheers,
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #21
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    I took out the code below which was creating the new record.
    Code:
    'If IsActive = True Then
    'Me.AccountClosed = Null
    'Me.RecordLock = False
    'Else
    'Me.AccountClosed = Now()
    'Me.RecordLock = True
    'End If
    That allows me when i hit Add to go to new record and I can Undo, However.... I get two of the same errors
    When i try to type in any new info...
    "Field Cannot Be Updated", If I click OK, then it comes up again, click OK and I can enter info into form.
    I assume there are two of something it doesnt like in the OnCurrent event? So i went through and ' out
    code blocks to see what if any effected that and no luck.... Its not locked, no other users so something is
    locking the fields for some reason from updating till i click oK twice? Any idea what so ever?
    Thanks
    Dave

  7. #22
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Hi Dave,

    Maybe have a look at the post #20 and the file I uploaded there...

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #23
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Gicu
    Thank you so much... I went over changes and wow, it works like a charm...
    I am very curious of why the foms current event gets triggered twice? Is there a good video somewhere that explains the step thru process?
    I have tried to do this and i cant wrap my head around it, it doesnt seem to give an error or anything when doing it? Just curious if there
    is a video out there that explains this in good english, lol,
    I have googled it, have watched a few but they really dont explain it for dummies!

    Again,
    Thank you for the assistance and time
    Dave

  9. #24
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,111
    Hi Dave,

    Glad to hear it works OK for you.

    For the undo button you are navigating to the previous record which triggers the Current event then you explicitly call it again in your code. To step through I simply put a break where I want to start then press F8 to advance one line at the time; when I get to a loop I usually put another break just after it and click the Run button.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. User formatted autonumber question
    By Ranger7913 in forum Database Design
    Replies: 3
    Last Post: 02-23-2016, 09:30 PM
  2. Question about Autonumber
    By Reaper in forum Programming
    Replies: 13
    Last Post: 01-01-2015, 09:46 PM
  3. What is the AutoNumber function in a Query?
    By supracharger in forum Queries
    Replies: 1
    Last Post: 06-01-2012, 10:07 AM
  4. AutoNumber Question
    By Rick5150 in forum Access
    Replies: 9
    Last Post: 10-16-2011, 01:43 PM
  5. Complex VBA Autonumber question
    By Lockrin in forum Access
    Replies: 2
    Last Post: 04-13-2010, 01:25 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