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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems Closing Form

Status
Not open for further replies.

papic1972

Technical User
Apr 10, 2003
209
AU
I have the following code in the Unload event of a form:

If Me.NewRecord And IsNull(Me.PackSize) Then

MsgBox "Check Pack Sizing on " & Me.ProductDescription & "." & vbCrLf & "If unsure enter '0'.", vbCritical, "Missing Data Message from ZP"
Me.PackSize.SetFocus
Cancel = True
Exit Sub
Else
DoCmd.Close

End If


I want the user to be able to close the form if no new record has been added. I keep getting a 'Close action has been cancelled' error.
Can anyone see in my code why this would be happening?
Thanks in advance.
 
Insert this code in an exit button:

If Me.NewRecord And IsNull(Me.PackSize) Then
MsgBox "Check Pack Sizing on " & Me.ProductDescription & "." & vbCrLf & "If unsure enter '0'.", vbCritical, "Missing Data Message from ZP"
Me.PackSize.SetFocus
Exit Sub
endif
DoCmd.Close
 
How are ya papic1972 . . .

If the Unload event is triggered it means the [blue]form is already in the process of closing[/blue]. No need to send another close command. Try the following in the [blue]Unload[/blue] event:
Code:
[blue]   Dim Msg As String, Style As Integer, Title As Integer, DL As String
   
   DL = vbNewLine & vbNewLine
   
   If Me.NewRecord And IsNull(Me.PackSize) Then
      Msg = "Check Pack Sizing on " & Me.ProductDescription & "." & DL & _
            "If unsure enter '0'."
      Style = vbCritical + vbOKOnly
      Title = "Missing Data Message from ZP"
      MsgBox Msg, Style, Title
      Me.PackSize.SetFocus
      Cancel = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top