PDA

View Full Version : Message Box trouble



TButhe
07-18-2005, 01:32 PM
I am having trouble with a message box. I have a user form that pops up if they don't make a selection on the UF and try to click OK. Why won't the message box go away? What am I doing wrong/missing? I know you all can figure this out in a flash, I'm just not getting it. :banghead: Here's my code:


Private Sub CommandButton1_Click()
Dim Answer As String
ActiveSheet.Unprotect Password:="cfs"
If BkDepType.OptionButton1.Value = True Then
Range("m2").Value = "99-999-10010-000 - General CHECKING - Clearing"
Unload Me
End If
If BkDepType.OptionButton2.Value = True Then
Range("M2").Value = "99-999-12857-000 - A/R Unapplied MEDICARE Clearing"
Unload Me
End If
If BkDepType.OptionButton3.Value = True Then
Range("M2").Value = "99-999-12857-0000 - A/R Unapplied MEDICAID Clearing"
Unload Me
End If
If BkDepType.OptionButton4.Value = True Then
Range("M2").Value = "99-999-21061-0000 - Accounts Receivable Refund"
Unload Me
End If
If BkDepType.OptionButton1.Value = False & BkDepType.OptionButton2.Value = False _
& BkDepType.OptionButton3.Value = False & BkDepType.OptionButton4.Value = False Then
Answer = MsgBox("You must choose a deposit type. Click OK to select a deposit type or click Cancel to close the form." _
, vbOKCancel, "Deposit Type!")
If Answer = vbOK Then
BkDepType.Show
ElseIf Answer = vbCancel Then
Unload Me
Unload BkDepType
Application.DisplayAlerts = wdAlertsNone
ActiveWorkbook.Close xlSaveChanges = False
Application.DisplayAlerts = wdAlertsAll
Exit Sub
End If
End If
End Sub

mdmackillop
07-18-2005, 01:39 PM
Hi Tracy,
I don't believe you can use ampersand "&" to mean And in the following line. Try replacing them with And. I don't know if there is a limit of And functions that can be joined.

If BkDepType.OptionButton1.Value = False & BkDepType.OptionButton2.Value = False & BkDepType.OptionButton3.Value = False & BkDepType.OptionButton4.Value = False Then

You could also add the option button values. True = -1, False = 0, if OB1+OB2+OB3+OB4=0 then MsgBox

Bob Phillips
07-18-2005, 01:47 PM
You can also cut the code down and make it more readable



Private Sub CommandButton1_Click()
Dim Answer As String
ActiveSheet.Unprotect Password:="cfs"
With BkDepType
If .OptionButton1.Value Then
Range("m2").Value = "99-999-10010-000 - General CHECKING - Clearing"
Unload Me
ElseIf .OptionButton2.Value Then
Range("M2").Value = "99-999-12857-000 - A/R Unapplied MEDICARE Clearing"
Unload Me
End If
If .OptionButton3.Value Then
Range("M2").Value = "99-999-12857-0000 - A/R Unapplied MEDICAID Clearing"
Unload Me
ElseIf .OptionButton4.Value Then
Range("M2").Value = "99-999-21061-0000 - Accounts Receivable Refund"
Unload Me
Else
Answer = MsgBox("You must choose a deposit type. " & _
"Click OK to select a deposit type or click Cancel to close the form.", _
vbOKCancel, "Deposit Type!")
If Answer = vbOK Then
.Show
Else
Unload Me
Unload BkDepType
Application.DisplayAlerts = wdAlertsNone
ActiveWorkbook.Close xlSaveChanges = False
Application.DisplayAlerts = wdAlertsAll
Exit Sub
End If
End If
End With
End Sub

TButhe
07-18-2005, 01:48 PM
Thanks, I was wondering about that. I keep getting an error on the line that says
BkDepType.Show where i am trying to show the UF after the user clicks ok on the Msgbox. How do I close or hide the msgbox after they click OK?

I hope I am being somewhat clear I am in too much of a hurry.

Bob Phillips
07-18-2005, 01:51 PM
Thanks, I was wondering about that. I keep getting an error on the line that says
BkDepType.Show where i am trying to show the UF after the user clicks ok on the Msgbox. How do I close or hide the msgbox after they click OK?

I hope I am being somewhat clear I am in too much of a hurry.

MsgBox automatically closes when a button is clicked.

TButhe
07-18-2005, 02:00 PM
That is what I thought but if I click OK on the msg box and then make a choice the box shows up again and I have to click Ok to close it. Boy, if anyone can mess things up it is ME!:omg2:

mdmackillop
07-18-2005, 02:18 PM
Try the attached, based on Bob's code
Note: I've replaced Close with a message for testing purposes.

TButhe
07-18-2005, 02:27 PM
Thanks! I will try it and get back to you tomorrow. Have a great night.

TButhe
07-19-2005, 07:35 AM
Thanks, xld and mdmackillop that is what I needed. I can relax now!! :bubblebat I am so glad I came across this site - it rocks!! :guitar2:

This one is closed.