Consulting

Results 1 to 6 of 6

Thread: Custom form with custom controls - how to get selected values via vba

  1. #1
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    5
    Location

    Custom form with custom controls - how to get selected values via vba

    I created a custom form in outlook 2007. I added 2 combobox controls to custom tab. How do I get the selected value from the controls?

    I can access the values of the standard Appointment fields

    Dim oAppt As Outlook.AppointmentItem
    .
    oAppt.Categories 'Category
    oAppt.Subject) 'Subject
    oAppt.Location 'Location

    I created a Custom form that includes:
    • Appointment - Standard tab - I can get values from this tab as stated above
    • Request demographics - new tab i created that contains 2 combobox controls
      • Combobox1 -
      • Combobox2

    I need to know how to get the values of the user defined fields Combobox1 and Combobox2. Any Help would be greatlyt appreciated.

    Thank you.

  2. #2
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    5
    Location
    Code that I have so far.

    Sub FindApptsInTimeFrame()
        Dim myStart, myEnd As Date
        Dim oCalendar As Outlook.Folder
        Dim oItems As Outlook.Items
        Dim oResItems As Outlook.Items
        Dim oAppt As Outlook.AppointmentItem
        Dim strRestriction As String
        Dim strApptCategories
        ' Set 20 as the number of supported categories, should get that number per user's decision.
        Dim strAllCategories(0 To 20) As String
        Dim iTotalCount As Integer
        Dim iDurationPerCategory(0 To 20) As Integer
        Dim strListSep As String
        Dim i, j, iNumApptCategories
        Dim blnExists As Boolean
        Dim dtDiff As Long
        Dim fso As New FileSystemObject
        ' Declare a TextStream.
        Dim stream As TextStream
        ' Create a TextStream.
        Set stream = fso.CreateTextFile("C:\Users\nbksog8\test.csv", True)
     
        'Hard-code the reporting dates just for simplicity in testing.
        myStart = DateValue("11/11/2013")
        myEnd = DateValue("11/15/2013")
             
        Set oCalendar = Application.Session.GetDefaultFolder(olFolderCalendar)
        
       
        'Set oItems = oCalendar.Items
        
         Set oItems = Session.GetDefaultFolder(olFolderCalendar).Items.Parent.Folders("RUIT").Items
         
         
        'Include all recurring calendar items -
        'master appointments as well as recurring appointments.
        oItems.IncludeRecurrences = True
        oItems.Sort "[Start]"
             
        'Specify the filter this way to include appointments that overlap
        'with the specified date range but do not necessarily fall entirely within
        'the date range.
        'Date values in filter do not explicitly include minutes.
        strRestriction = "[Start] <= '" & myEnd _
        & "' AND [End] >= '" & myStart & "'"
        
        '''Debug.Print strRestriction
         
        'Restrict the Items collection.
        Set oResItems = oItems.Restrict(strRestriction)
        'Sort
        oResItems.Sort "[Start]"
         
        'Reformat myStart and myEnd to account for minutes.
        myStart = #11/11/2013 7:59:00 AM#
        myEnd = #11/15/2013 6:00:00 PM#
         
        iTotalCount = 0
        'Get the separator between categories from the Windows registry.
        
        strListSep = WSHListSep()
        
        For Each oAppt In oResItems
            
            
           Debug.Print oAppt.Start & "~", oAppt.Categories & "~", oAppt.Subject & "~", oAppt.Location; "~", oAppt.Duration / 60
           ''''''' Open notepad to save data '''''
           
            
            stream.Write ("10453770")       'Person Number
            stream.Write ("~")
            stream.Write (myEnd)            'Week
            stream.Write ("~")
            stream.Write (oAppt.Categories) 'Category
            stream.Write ("~")
            stream.Write (oAppt.Subject)    'Subject
            stream.Write ("~")
            stream.Write (oAppt.Location)   'Location
            stream.Write ("~")
            stream.Write (oAppt.Duration / 60) 'Time
          
                   
                         
            stream.WriteLine ""
            
          
    
           
           
           
           
            
            ' Get the list of categories specified for this appointment.
           strApptCategories = Split(oAppt.Categories, strListSep)
           iNumApptCategories = UBound(strApptCategories)
            
            ' An appointment that doesn't have a category (with iNumApptCategories being 0) skips this loop.
            For i = 0 To iNumApptCategories
                ' Check if category exists in master array strAllCategories.
                blnExists = False
                If iTotalCount > 0 Then
                    ' Master array already has some categories, see if there's a match or should add category
                    For j = 0 To iTotalCount - 1
                        If Trim(strAllCategories(j)) = Trim(strApptCategories(i)) Then
                            blnExists = True
                            Exit For
                        End If
                    Next
                    If blnExists = False Then
                        ' First time this category appears, add category to master array and start tallying time.
                        If iTotalCount >= 20 Then
                            MsgBox "The maximum number of categories has been reached."
                            GoTo Dump
                        End If
                        iTotalCount = iTotalCount + 1
                        strAllCategories(iTotalCount - 1) = Trim(strApptCategories(i))
                        
                        ' Check if the appointment is entirely within the date range.
                        If oAppt.Start >= myStart Then
                            If oAppt.End <= myEnd Then
                                iDurationPerCategory(iTotalCount - 1) = oAppt.Duration
                            Else
                                dtDiff = DateDiff("n", myEnd, oAppt.End)
                                iDurationPerCategory(iTotalCount - 1) = oAppt.Duration - dtDiff
                            End If
                        Else
                            dtDiff = DateDiff("n", oAppt.Start, myStart)
                            iDurationPerCategory(iTotalCount - 1) = oAppt.Duration - dtDiff
                        End If
                    Else
                        ' Category already in master array, just tally the time for the category.
                        ' Check if the appointment is entirely within the date range.
                        If oAppt.Start >= myStart Then
                            If oAppt.End <= myEnd Then
                                iDurationPerCategory(j) = iDurationPerCategory(j) + oAppt.Duration
                            Else
                                dtDiff = DateDiff("n", myEnd, oAppt.End)
                                iDurationPerCategory(j) = iDurationPerCategory(j) + oAppt.Duration - dtDiff
                            End If
                        Else
                            dtDiff = DateDiff("n", oAppt.Start, myStart)
                            iDurationPerCategory(j) = iDurationPerCategory(j) + oAppt.Duration - dtDiff
                        End If
                    End If
                Else
                    ' First category in master array of categories, start master array and start count of categories.
                    iTotalCount = 1
                    strAllCategories(0) = Trim(strApptCategories(i))
                    
                    ' Check if the appointment is entirely within the date range.
                    If oAppt.Start >= myStart Then
                        If oAppt.End <= myEnd Then
                            iDurationPerCategory(0) = oAppt.Duration
                        Else
                            dtDiff = DateDiff("n", myEnd, oAppt.End)
                            iDurationPerCategory(0) = oAppt.Duration - dtDiff
                        End If
                    Else
                        dtDiff = DateDiff("n", oAppt.Start, myStart)
                        iDurationPerCategory(0) = oAppt.Duration - dtDiff
                    End If
                End If
            Next
        Next
          'Close the file.
           stream.Close
        'List all unique categories and count
    Dump:
      '  For j = 0 To iTotalCount - 1
      '      Debug.Print strAllCategories(j), iDurationPerCategory(j)
      '  Next
    
    End Sub
    
    Function WSHListSep()
    
        Dim objWSHShell
        Dim strReg
        strReg = "HKCU\Control Panel\International\sList"
        Set objWSHShell = CreateObject("WScript.Shell")
        WSHListSep = objWSHShell.RegRead(strReg)
        Set objWSHShell = Nothing
    
    
    End Function

  3. #3
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  4. #4
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    5
    Location
    I added the code to my project but I am getting an error. It is hard to tell what the actual error is but from what i can tell objPage is empty


    Set objPage = Item.GetInspector.ModifiedFormPages("Request Demographics")
    Set objControl = objPage.Controls("ComboBox1")
    MsgBox "The value in the " & objControl.name & "control has changed to " & objControl.Value & "."

  5. #5
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    5
    Location
    Can anyone help? It seems it should be a simple thing to get values from a custom dropdown list?

  6. #6
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    5
    Location
    Answer to my question

    oAppt.UserProperties("ClientManger")

Posting Permissions

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