Close form button stopped working

dfedosoff

New member
Local time
Today, 08:38
Joined
Jul 12, 2008
Messages
8
I have a ADD New Record form that I created. The data enters correctly (I see the data in the table - all required fields are there but when I go and click on my Close Button that I created it doesn't work. The other buttons do work but his one will not close the form down. Any idea what would cause this? The only thing I was fooling around with prior to this was my Reference List.

Button code below:

Private Sub CloseME_Click()
If IsNull(Me.VisitDate) Then ''MOVED THIS OVER Or IsNull(Me.TypeOfVisit)
Dim Response As String
Response = MsgBox("MISSING DATA: VISIT DATE. Records without this information are deleted. Do you want to save this visit?", vbYesNo + vbCritical, "Save Visit")
If Response = vbYes Then MsgBox "Please enter in the VISIT DATE." ' User chose Yes.
If Response = vbNo Then
McrDeleteNullVisit
DoCmd.Close
Else
DoCmd.Close
End If
End If
End Sub
 
Can you just comment out all the code and just run DoCmd.Close to see if it works.
 
Code:
Private Sub CloseME_Click()

[COLOR="Red"][B]If IsNull(Me.VisitDate) Then[/B]
[/COLOR]  
  Dim Response As String
  Response = MsgBox("MISSING DATA: VISIT DATE. Records without this information are deleted. Do you want to save this visit?", vbYesNo + vbCritical, "Save Visit")

   If Response = vbYes Then MsgBox "Please enter in the VISIT DATE." ' User chose Yes.

   [COLOR="Blue"][B]If Response = vbNo Then
     McrDeleteNullVisit
     DoCmd.Close
   Else
     DoCmd.Close
   End If[/B][/COLOR]


[COLOR="Red"][B]End If[/B][/COLOR]

End Sub
Your first If...Then is matched by the final End If. This being true, if VisitDate is populated, i.e. has a value entered, Your If...Then
Code:
[COLOR="Blue"][B]If Response = vbNo Then
     McrDeleteNullVisit
     DoCmd.Close
   Else
     DoCmd.Close
   End If[/B][/COLOR]
is never executed and your Form will not close.

Linq ;0)>
 
Thank you so much - makes sense and I never saw that. I always thought each IF had to have and End if. I will fix that - thanks for you help.
 
No, if the entire If...Then exists on a single line, such as your
Code:
If Response = vbYes Then MsgBox "Please enter in the VISIT DATE." ' User chose Yes.
then you not only do not need the End If with it, but you cannot use it, or the IF...End Ifs will be unbalanced and pop an error.

But that's not your problem, here. The problem is that you're bypassing the code I put in blue when the first If..Then is False.

Linq ;0)>
 
Last edited:
Now I get it! Thanks for explaining it twice to me. Nesting has always been a problem for me.
 

Users who are viewing this thread

Back
Top Bottom