Results 1 to 2 of 2

Thread: warning message

  1. #1
    Join Date
    Sep 2007
    Posts
    148

    Unanswered: warning message

    OK! something Very weird is happening to my Close and Delete routine.

    I have been using the following 2 routine to delete record with multiple for several apps. I don't have any problem until now. Cannot figure out what is wrong with it and I hope someone will be able to tell me what did I do wrong.

    First, when a user Click the Close button. It will called up the cmdClose_Click. If the user choose to NOT save the record into the database, the Delete routine will be called out. Well, all is well. The Delete routine delete all the appropriate record in all the table. However, It keeps give me a warning

    " The field "tblContractItem.ContractID" cannot contain a Null value because the Required property for this field is set to True. Enter a value in this field" with a "OK" and "help" button.

    I can see why because I have deleted the record. However, I thought I have set the warning message to false. Do not understand why this warning keep popping up.
    Any help is greatly appreciated.
    **************************************************
    Private Sub cmdClose_Click()
    DoCmd.SetWarnings False


    On Error GoTo Err_cmdClose_Click



    If MsgBox(" Would you like to commit this Contract into the database?", vbYesNo) = vbNo Then
    Call cmdDelete_Click
    DoCmd.Close acForm, "frmContractNEW", acSaveNo
    DoCmd.Close acForm, "frmContractAddNEW"


    Else

    Call cmdSave_Click

    DoCmd.Close acForm, "frmContractNEW", acSaveNo
    DoCmd.Close acForm, "frmContractAddNEW"
    End If



    Exit_cmdClose_Click:
    Exit Sub

    Err_cmdClose_Click:
    MsgBox Err.Description
    Resume Exit_cmdClose_Click

    End Sub

    ************************************

    Private Sub cmdDelete_Click()


    On Error GoTo Err_cmdDelete_Click

    Dim db As Database
    Dim rs1 As DAO.Recordset
    Dim rs2 As DAO.Recordset


    Set db = CurrentDb()




    '-----open the tblContractItemPayment table and delete the old entries

    Set rs2 = db.OpenRecordset("Select * FROM tblContractItemPayment ", dbOpenDynaset, dbSeeChanges, dbOptimistic)

    If Not rs2.EOF Then

    rs2.MoveFirst

    Do Until rs2.EOF
    If rs2.Fields(0) = Forms!frmContractNEW!ContractID Then
    rs2.Delete
    End If
    rs2.MoveNext
    Loop

    End If
    rs2.Close
    Set rs2 = Nothing
    '-----open the tblContractItem table and delete the old entries

    Set rs1 = db.OpenRecordset("Select * FROM tblContractItem ", dbOpenDynaset, dbSeeChanges, dbOptimistic)

    If Not rs1.EOF Then

    rs1.MoveFirst

    Do Until rs1.EOF
    If rs1.Fields(0) = Forms!frmContractNEW!ContractID Then
    rs1.Delete
    End If
    rs1.MoveNext
    Loop

    End If
    'close the recordset

    rs1.Close



    ' release the memory back to the system

    Set rs1 = Nothing
    Set db = Nothing

    DoCmd.SetWarnings False

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    Exit_cmdDelete_Click:
    Exit Sub

    Err_cmdDelete_Click:
    MsgBox Err.Description
    Resume Exit_cmdDelete_Click

    End Sub
    Last edited by sweetmail; 10-04-09 at 09:25.

  2. #2
    Join Date
    Mar 2007
    Posts
    277
    In what form is this code located and what is the RecordSource of this form?
    RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP, ac07, ac10 - WinXP Pro, Win7 Pro
    Please reply to this forum so all may learn.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •