Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help With Error Trap? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I have the following code to force the operator to click my Close button on the form when they click Form X by mistake.

    This seems to work however, how do I trap and eliminate the following message?

    The close action was canceled

    Thanks, John



    <pre>Private Sub Form_Unload(Cancel As Integer)

    On Error GoTo Err_Form_Unload

    If fOKToClose = False Then
    'MsgBox "You must use the Close button (bottom of form) to close the form!"
    Call Close_Form_Click
    Cancel = Not fOKToClose ' disable close button, force user to use Close button

    End If

    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Set db = CurrentDb
    Set rst = db.OpenRecordset("tblLastUsed", dbOpenDynaset)
    If rst.RecordCount = 0 Then
    rst.AddNew
    Else
    rst.MoveFirst
    rst.Edit
    End If
    ' rst!LastUsedRecordBP = Me.Recordset.AbsolutePosition
    rst!LastUsedRecordRT = Me!lngRevTranID
    rst.Update
    rst.Close ' Close recordset
    Set rst = Nothing ' Release record object
    Set db = Nothing ' Release database object

    Exit_Form_Unload:
    Exit Sub

    Err_Form_Unload:
    MsgBox Err.Description & " " & Err.Number

    Resume Exit_Form_Unload

    End Sub
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Help With Error Trap? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    You haven't told us what Closr_Form_Click does.

    You should put a line Exit Sub immediately below Cancel = Not fOKToClose.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help With Error Trap? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    The Close button checks to see if mandatory fields on the form were filled in and if everything is OK closes the form.

    I still get the "The Close action was canceled" message

    Any thoughts?

    John

    <pre>If fOKToClose = False Then
    Call Close_Form_Click
    Cancel = Not fOKToClose ' disable close button, force user to use Exit
    Exit Sub
    End If
    </pre>


    <pre>Private Sub Close_Form_Click()
    On Error GoTo Err_Close_Form_Click

    Dim intMsgDialog As Integer
    Dim intResponse As Integer
    Dim strTitle As String

    Dim lngCount As Long
    lngCount = Me.[Fee Count]

    If lngCount < 2 Then
    MsgBox "You must have a balanced transaction with minimun of: " _
    & vbLf & vbCr & vbLf & vbCr & _
    " 1. One Charge Line and " _
    & vbLf & vbCr & _
    " 2. One Payment Line. " _
    & vbLf & vbCr & vbLf & vbCr & _
    "You must Add the Transaction as requested before Saving, or " _
    & vbLf & vbCr & vbLf & vbCr & _
    "select RED Delete buttom below if Add function is not desired, " _
    & vbLf & vbCr & vbLf & vbCr & _
    "and you want finish Point-of-Sale and returns all buttons."

    Exit Sub
    End If

    strTitle = "CLOSE FORM?"
    intMsgDialog = vbYesNo + vbQuestion + vbDefaultButton2

    intResponse = MsgBox("You requested to Close this form, select Yes if this " & _
    "is what you want to do!" _
    & vbCrLf & vbCrLf & "Copyright 2002 by (NBS)", _
    intMsgDialog, strTitle)
    If intResponse = vbYes Then
    fOKToClose = True ' disable close button, force user to use Exit
    DoCmd.Close acForm, Me.Name, acSaveNo
    Else ' Does the following if user changes her mind.
    Me.cboLookupSequence.SetFocus
    End If

    Exit_Close_Form_Click:
    Exit Sub

    Err_Close_Form_Click:
    MsgBox Err.Description & " " & Err.Number
    Resume Exit_Close_Form_Click

    End Sub
    </pre>


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Help With Error Trap? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I see no reason to call Close_Form_Click in the On Unload event of the form. I would remove the line

    Call Close_Form_Click

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help With Error Trap? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    OK

Posting Permissions

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