+ Reply to Thread
Results 1 to 6 of 6

Get UserForm checkbox caption and pass to another UserForm on click or mouse down

Hybrid View

  1. #1
    Registered User
    Join Date
    11-02-2013
    Location
    Tulsa
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Get UserForm checkbox caption and pass to another UserForm on click or mouse down

    thanks AlphaFrog. Is there a way to make a loop or while statement? There are 16 checkboxes to get captions from just for the tasks. Im trying to avoid writing the code that many times!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Get UserForm checkbox caption and pass to another UserForm on click or mouse down

    Quote Originally Posted by tulsaguy71 View Post
    thanks AlphaFrog. Is there a way to make a loop or while statement? There are 16 checkboxes to get captions from just for the tasks. Im trying to avoid writing the code that many times!
    This puts your FrameOQ Checkboxes in an array and traps their events in a class module.

    Put this in the UserForm1 code module
    '
    Private OQCheckBoxes() As New OQCB_Events_class  'Place at the top of UserForm1 code module
    '
        
    Private Sub UserForm_Initialize()
        
        Dim Counter As Long, c As Control
        'Add the OQ Checkboxes to the array
        For Each c In Me.FrameOQ.Controls
            If TypeOf c Is MSForms.CheckBox Then
                Counter = Counter + 1
                ReDim Preserve OQCheckBoxes(1 To Counter)
                Set OQCheckBoxes(Counter).OQCheckBox = c
            End If
        Next c
        Set c = Nothing
        
    End Sub

    Insert a new class module and paste this code in it.
    Name the Class Module OQCB_Events_class

    ' OQCB_Events_class module
    ' Event procedures for the FrameOQ CheckBoxes (OQCheckBoxes)
        
    Public WithEvents OQCheckBox As MSForms.CheckBox
        
    Private Sub OQCheckBox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        
        If OQCheckBox.Value = False Then
            If MsgBox(Prompt:="Are you sure you want to make changes? ", _
                      Buttons:=vbYesNo, Title:="Confirm Action") = vbYes Then
                OQCheckBox.Value = True
                With frmOQDate
                    .lbOQtaskNum.Caption = OQCheckBox.Caption
                    .txtOQdate.Value = OQCheckBox.ControlTipText   'You could store a date in the .Tag property as well
                    .txtOQEmpName.Value = UserForm1.txtEditEmpName
                    .txtOQposition.Value = UserForm1.cboxEditPosition
                    .txtOQVeriforce.Value = UserForm1.txtEditVeriforce
                    .Show
                End With
            End If
        End If
        
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 03-06-2013, 12:52 PM
  2. Replies: 0
    Last Post: 11-15-2012, 12:29 PM
  3. center userform caption
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-08-2009, 10:16 AM
  4. Userform Caption
    By Jason Zischke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2006, 03:55 AM
  5. How to format Userform caption?
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2005, 02:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1