A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problems Deleting a record.



 
 
Thread Tools Display Modes
  #1  
Old July 14th, 2004, 06:54 PM
Kris L.
external usenet poster
 
Posts: n/a
Default 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  
Old July 15th, 2004, 03:06 AM
Allen Browne
external usenet poster
 
Posts: n/a
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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


All times are GMT +1. The time now is 03:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.