Results 1 to 4 of 4
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    Using code to get a record out of the edit mode while retaining changes already made

    This is a bit complicated. I have a tabular form “F_EditCard” which has as its recordsource table “Phases”. Each record in Phases has two text fields, Ph_Heading and Ph_ResponsePrompt. Both these fields are represented on the form F_EditCard and they can be updated. On the form there is a button “CancelChanges”, which when clicked runs a routine which first deletes all the records in Phases and then adds records back into the table which contain backup data, then does a Me.Requery. I have noticed that sometimes this routine generates a “Record Deleted” error and sometimes it doesn’t. It took me a long time to figure out the pattern.

    The form F_EditCard has record selectors. Let’s say I am on record 3. When I put the cursor into the box corresponding to field Ph_Heading in record 3, and then change the text, the triangle on the record selector of record 3 changes to an icon which looks sort of like a yellow pencil. If I now click the CancelChanges button I get the error mentioned above. But .. if I first move the cursor away from record 3 to some other record and don’t change that other record the yellow pencil on the record selector of record 3 dissappears. Now I can push the CancelChanges button and the data reverts to the original and I don’t get the error. It would appear that if I don’t move the cursor away from a record I am editing, that record is in a sort of limbo state and if I try to delete it the system will not like it. What I would like to do is put into the code of Sub CancelChanges_Click() something that has the effect of telling the program “If a record is in the middle of being edited, accept the edits so far and get that record out of the edit mode”.
    Any suggestions?


    Thanks in advance

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sub CancelChanges_Click()
    What is the code for the above sub?

    Without seeing the code, try adding the line:
    Code:
    Me.Dirty = FALSE
    towards the beginning of the code

  3. #3
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    Steve,

    I don't understand it, but that seems to clear up the problem. Thanks.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    From Help on the DIRTY property (NOT EVENT)
    You can use the Dirty property to determine whether the current record has been modified since it was last saved. Read/write Boolean.
    When a record is saved, Microsoft Access sets the Dirty property to False. When a user makes changes to a record, the property is set to True.
    When you set the form Dirty property to false, using
    Code:
    Me.Dirty = FALSE
    you actually save any adds/edits to the form. It will change the "pencil" icon to the "triangle" icon, just as if you did something to save the change(s).

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

Similar Threads

  1. Replies: 4
    Last Post: 04-08-2014, 09:36 AM
  2. Replies: 4
    Last Post: 11-26-2013, 10:47 AM
  3. Replies: 5
    Last Post: 11-06-2013, 02:49 PM
  4. Replies: 21
    Last Post: 08-05-2013, 06:23 AM
  5. Replies: 2
    Last Post: 09-01-2011, 10:48 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