View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default VBA Beginner: Help with Checkboxes on created User Form

Forgot the second part:
The code you have applies to a standard Visual Basic form, but not a
Microsoft Forms UserForm as implemented in VBA. I know, confusing, but there
are different kinds of forms in different environments. VBA forms don't have
control menus or a CloseMode as a parameter for the _Click procedure.
I am not aware of a way to do exactly what you want; perhaps someone else
is. But you may be able to achieve the effect this way:

Private OKToQuit As Boolean ' determines if button pressed to exit

Private Sub Cancel_Click()
OKToQuit = True
Me.Hide
End Sub

Private Sub Apply_Click()
MsgBox "Button pressed; Apply choices"
OKToQuit = True
Me.Hide
End Sub

Private Sub UserForm_Terminate()
' Check if button was pressed:
If Not OKToQuit Then ' If not, prompt user:
DoIt = MsgBox("Do you want to use or ignore your selections?" _
& vbCrLf & "(Press OK to use selections, Cancel to ignore)",
vbOKCancel, "USE SELECTIONS?")
If DoIt = vbOK Then ' User said go ahead:
MsgBox "Closed form: Apply settings"
End If
End If
End Sub

Replace the message boxes with the code you want to run
--
- K Dales


"MarianneR" wrote:


Hi. I'm basically teaching myself some VBA skills when I need them. So
please, bear with me.

I've created a user form for an Excel spreadsheet for fairly
inexperienced users. I have combo boxes and text boxes that work
perfectly well. However, I'm trying to add a check box and I guess
I'm not quite sure how they work. Is the checkbox more an individual
thing? Does it work in such a way that each item I want needs its own
checkbox?

My user form _might_ look something like this:

Patient Name: (text box)
Diagnosis: (combo box - list of 10)
CoMorbidities: (checkbox - list of 9 things, more than one can be
chosen)

Basically, I was wondering if it would be possible to have a checkbox
like this on a user form. Can I create something where you can select
more than one option and then have it drop into my spreadsheet? I keep
looking for this, but I'm not even aware if it's possible.

Another question I have is that if my a user closes the form without
clicking on the "enter data" or "close form" command buttons, a
"compile error" occurs. Here's the code that I have (from an example I
found):
Private Sub UserForm_Click()
(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If

The part in parenthesis turns red after the error.

Your patience and any help is appreciated. I hope I've provided enough
information.

Thank you in advance.
Marianne


--
MarianneR
------------------------------------------------------------------------
MarianneR's Profile: http://www.excelforum.com/member.php...fo&userid=6253
View this thread: http://www.excelforum.com/showthread...hreadid=475191