Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Prevent user from closing form (Access 2000 all updates)

    Here is code that I have on the BeforeUpdate event for a form...

    If IsNull(Me.DatePurchased) And Not IsNull(Me.Purchaser) Then
    Select Case MsgBox("You have entered a plot sale and a Purchaser" _
    & vbCrLf & " but have not completed a Date Purchased." _
    & vbCrLf & "" _
    & vbCrLf & " Do you wish to record a sale?" _
    & vbCrLf & "" _
    & vbCrLf & "" _
    , vbYesNo Or vbExclamation Or vbDefaultButton1, "Date Purchased Needed")
    Case vbYes
    Call MsgBox(" Thank you." _
    & vbCrLf & "Please enter a Date Purchased." _
    , vbExclamation Or vbDefaultButton1, "Record of Purchase continuing")
    Me.DatePurchased.SetFocus
    Cancel = True
    Case vbNo
    Call MsgBox(" Thank you." _
    & vbCrLf & "The record will be cancelled." _
    , vbExclamation Or vbDefaultButton1, "Cancelling record")
    Me.Undo
    Cancel = True
    Me.PlotID.SetFocus
    End Select
    End If

    If IsNull(Me.DateReturned) And Me.Returned = True Then
    Call MsgBox("The ""RETURNED"" box has been checked." _
    & vbCrLf & " Please enter a Date Returned!" _
    , vbExclamation, "Date Returned missing")
    Me.Returned = True
    Cancel = True
    Me.DateReturned.SetFocus
    End If

    If Not IsNull(Me.DateReturned) And Me.Returned = False Then
    Call MsgBox("You have entered a date in Date Returned" _
    & vbCrLf & " but did not check the ""RETURNED"" box." _
    & vbCrLf & "" _
    & vbCrLf & " It will be checked automatically." _
    , vbExclamation, """RETURNED"" not checked")
    Me.Returned = True
    Cancel = True
    Me.Returned.SetFocus
    End If

    This code works fine if proceeding from one record to another...BUT it fails if the user presses the "Return to Main Menu" command button. The messages still appear but then the form closes rather than setting focus to the respective controls as called for by the code.

    I have tried placing the same code on the Unload event for the form but to no avail.

    Any suggestion would be helpful.

    Thanks.

    Tom

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent user from closing form (Access 2000 all updates)

    What if you put this modified code in the on click event of your Return to Main Menu :
    If IsNull(Me.DatePurchased) And Not IsNull(Me.Purchaser) Then
    Select Case MsgBox("You have entered a plot sale and a Purchaser" _
    & vbCrLf & " but have not completed a Date Purchased." _
    & vbCrLf & "" _
    & vbCrLf & " Do you wish to record a sale?" _
    & vbCrLf & "" _
    & vbCrLf & "" _
    , vbYesNo Or vbExclamation Or vbDefaultButton1, "Date Purchased Needed")
    Case vbYes
    Call MsgBox(" Thank you." _
    & vbCrLf & "Please enter a Date Purchased." _
    , vbExclamation Or vbDefaultButton1, "Record of Purchase continuing")
    Me.DatePurchased.SetFocus
    Cancel = True
    Exit Sub
    Case vbNo
    Call MsgBox(" Thank you." _
    & vbCrLf & "The record will be cancelled." _
    , vbExclamation Or vbDefaultButton1, "Cancelling record")
    Me.Undo
    Cancel = True
    Me.PlotID.SetFocus
    Exit Sub
    End Select
    End If

    If IsNull(Me.DateReturned) And Me.Returned = True Then
    Call MsgBox("The ""RETURNED"" box has been checked." _
    & vbCrLf & " Please enter a Date Returned!" _
    , vbExclamation, "Date Returned missing")
    Me.Returned = True
    Cancel = True
    Me.DateReturned.SetFocus
    Exit Sub
    End If

    If Not IsNull(Me.DateReturned) And Me.Returned = False Then
    Call MsgBox("You have entered a date in Date Returned" _
    & vbCrLf & " but did not check the ""RETURNED"" box." _
    & vbCrLf & "" _
    & vbCrLf & " It will be checked automatically." _
    , vbExclamation, """RETURNED"" not checked")
    Me.Returned = True
    Cancel = True
    Me.Returned.SetFocus
    Exit Sub
    End If
    DoCmd.Close acForm, Me.Name
    You'll have to set the Close Button property of the form to No to prevent the user to close the form by clicking the red cross close button in the upper right corner of the form
    Francois

  3. #3
    4 Star Lounger
    Join Date
    Oct 2003
    Location
    Guelph, Ontario, Canada
    Posts
    428
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Prevent user from closing form (Access 2000 all updates)

    Francois
    Thanks for your help. That's one thing I hadn't tried.

    I had to remove the Cancel = True lines, but then it worked well.

    Thanks again.

    Tom

Posting Permissions

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