Message box that stays after you've clicked yes

c02dm

Registered User.
Local time
Today, 06:52
Joined
Apr 12, 2005
Messages
18
Problem with message box that stays after i've clicked yes

I've got this yes/no message box that deletes an appointment. When i click yes to confirm delete, the box just stays there. I have to click yes again before it works. Clicking no works fine. Its like its going round the else if statement for vbYes twice. Does anyone know why this is happening? Heres a snippet of the related code. Thanks in advance.
Code:
If myYesNoQuestion(strDelete) = vbNo Then
myDisplayInfoMessage "Appointment kept on file"
'If the user decides not to delete the customer then appointment kept
Calendar3.SetFocus
'Sets the focus away to allow the rooms to be disabled
lstRoom1.Enabled = False
lstRoom2.Enabled = False
lstRoom3.Enabled = False
lstRoom4.Enabled = False
'Disables the rooms again

ElseIf myYesNoQuestion(strDelete) = vbYes Then
strSQL = "DELETE * FROM tblAppointment where [AppointmentID]= " & .Column(2)
'SQL to delete appointment from table
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
'Turn warning off, run SQL, turn them back on again
Code:
myDisplayInfoMessage "Appointment Deleted OK"
'If the user decides to delete the customer then record is deleted and a message is shown to prove that
Calendar3.SetFocus
'Sets the focus away to allow the rooms to be disabled
lstRoom1.Enabled = False
lstRoom2.Enabled = False
lstRoom3.Enabled = False
lstRoom4.Enabled = False
'Disables the rooms again

End If

End If
 
Last edited:
How about posting a snippet of code that includes the myYesNoQuestion() function; maybe the myDisplayInfoMessage() function as well.
 
My guess is that the focus must be moving off of the message box in question.
 
Here is the code you requested. I have commented out the code in my module relating to setting the focus away from the message but that doesn't seem to make any difference.

Public Function myYesNoQuestion(Question As String)

myYesNoQuestion = MsgBox(Question, vbQuestion + vbYesNo, "Opticians Database System")
'Creates a Yes, No message box

End Function

Public Function myDisplayInfoMessage(text As String)

myDisplayInfoMessage = MsgBox(text, vbOKOnly, "Opticians Database System")
'Creates a message box

End Function
 
By refering to myYesNoQuestion(strDelete) again in the elseif part are you not running the function again? So you will see it twice?
 
OK, cheers guys i've sorted it, just taken the myYesNoQuestion(strDelete) = vbYes out completely and used an Else not an ElseIf.

Many Thanks.
 

Users who are viewing this thread

Back
Top Bottom