Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When delete from form and subform will not allow input of new record 1

Status
Not open for further replies.

frantik

Technical User
Nov 9, 2002
93
0
0
GB
Hi

I have a delete button on my main form -which will delete a record from the main and subforms.

However when I try and add an additional record I get the error message:
You cannot add or change a record because a related record is required in table <name>. (Error 3201)

The record I have deleted is not present in any of the tables, the form is empty as if I had just opened it for input. I am eventually able to enter records but have to click to get rid of a message box telling me a related record is required about 10 times!!

The code behind the Delet button is:

Private Sub Command244_Click()
On Error Resume Next
DoCmd.SetWarnings False
Dim stDocName As String
Dim Msg, Style, Title, Help, Ctxt, Response, MyString

Msg = &quot;Do you really want to delete this record?&quot; ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = &quot;Record Delete&quot; ' Define title.

Response = MsgBox(Msg, Style, Title, Help, Ctxt)

If Response = vbYes Then

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

stDocName = &quot;Q_Deleterec&quot;
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

stDocName = &quot;Q_Deleterec&quot;
DoCmd.OpenQuery stDocName, acNormal, acEdit

Else ' User chose No.
MyString = &quot;No&quot; ' Perform some action.
End If

End Sub

Can someone please tell me how I can stop this happening?

thanks a lot

F.
 
if the current main record is a deleted record then you will get that msg when tyring to add a sub record

try

Me.refresh
or
Me.requery

OR

move to a new record (DoCmd.GoToRecord , , acNext)

at the end

 
Brill

Thanks

Me.refresh didn't work after the code - but did in the On Delete event of the main form!

Thanks loads

F.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top