If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Problems Deleting a record.
I have a simple Form that adds records to a table in my Database.
It has a command button called "Clear all Fields" which will (unbelievably) clear all the fields on the Form. To accomplish this I have the following Code in the form: Private Sub CMD_Clear_Fields_Click() 'Clears values for all items in form. confirmclearfield = MsgBox("Clearing the Fields will delete delete this record without saving. Do you wish to continue?", vbYesNo) If (confirmclearfield = 6) Then DoCmd.SetWarnings False DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 DoCmd.SetWarnings True End If End Sub Now, this command works perfectly IF the user has entered data in every field. However, if they have not entered data in a couple of the fields (fields which, incidentally, have relationships to child tables) and they try to clear, they get this error: "You cannot Add or Change a record because a related record is required in TBL_Efficiency." I know these relationships are set up correctly. They are very simple and (I think at least) I know what I'm doing. I think this is just related to something I need to do to workaround deleting the record when those fields are blank. Any suggestions you have would be greatly appreciated. Thx so much! Kris |
#2
|
|||
|
|||
Problems Deleting a record.
Undo the changes before you delete
If Me.Dirty Then Me.Undo End If If Not Me.NewRecord Then RunCommand acCmdDeleteRecord End If -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Kris L." wrote in message ... I have a simple Form that adds records to a table in my Database. It has a command button called "Clear all Fields" which will (unbelievably) clear all the fields on the Form. To accomplish this I have the following Code in the form: Private Sub CMD_Clear_Fields_Click() 'Clears values for all items in form. confirmclearfield = MsgBox("Clearing the Fields will delete delete this record without saving. Do you wish to continue?", vbYesNo) If (confirmclearfield = 6) Then DoCmd.SetWarnings False DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70 DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70 DoCmd.SetWarnings True End If End Sub Now, this command works perfectly IF the user has entered data in every field. However, if they have not entered data in a couple of the fields (fields which, incidentally, have relationships to child tables) and they try to clear, they get this error: "You cannot Add or Change a record because a related record is required in TBL_Efficiency." I know these relationships are set up correctly. They are very simple and (I think at least) I know what I'm doing. I think this is just related to something I need to do to workaround deleting the record when those fields are blank. Any suggestions you have would be greatly appreciated. Thx so much! Kris |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Deleting an indexed record from table | Bob Barry | Database Design | 2 | June 18th, 2004 04:18 PM |
Problems with record locking | Ronny Salomonsen | General Discussion | 0 | June 14th, 2004 09:37 AM |
Form Doesn't Go To New Record | Steve | New Users | 15 | May 16th, 2004 04:33 PM |
Form Does Not Go To New Record | Steve | New Users | 1 | May 12th, 2004 03:15 AM |
Avoid Creating A Duplicate Record | Mark | New Users | 4 | May 11th, 2004 01:52 AM |