none
Check that Microsoft Date and Time Picker is registered on PC RRS feed

  • Question

  • Hi, is there any way to check that Microsoft Date and Time Picker control is registered on PC using VBA code in macros?

    For example, when I run some code or form I would like to check whether it is registered before an error message about absence of this control comes up.

    Friday, February 22, 2019 12:28 PM

Answers

  • One way is test if you can create it -

    Dim objDTP As Object
    
    On Error Resume Next
    Set objDTP = CreateObject("MSComCtl2.DTPicker.2")
    MsgBox "DT Picker is registered: " & Not objDTP Is Nothing
    Increasingly the DTP and other ActiveX controls are less likely to be installed, better to use alternatives such as Jan Karel suggested.


    • Marked as answer by Vitalii P Tuesday, February 26, 2019 9:12 AM
    Tuesday, February 26, 2019 9:07 AM
    Moderator

All replies

  • Hi Vitalii P,

    Please refer to this article
    (This is written in Japanese. So, use machine translation.)

    (1) on Ribbon Menu -- [Developer] > [Insert] > [ActiveX Controls] > [More Controls]
          
    (2) Select [Microsoft Date and Time Picker Control] and [OK]

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Sunday, February 24, 2019 2:34 AM
  • Hi Ashidacchi,

    Thank you for the answer, but that is not what I am looking for.

    I look for the code to find out whether this control is registered in the system:

    if [code_to_find_out_that_date_time_picker_installed] = false then
    
    'run script to register it in the system
    
    end if

    So the thing I need is this part - [code_to_find_out_that_date_time_picker_installed]

    Monday, February 25, 2019 10:11 AM
  • Hi Vitalii P,

    Where do you place DateTimePicker? on worhksheet, on UserForm?
    Is what you want to do whether this control exists on worksheet/UserForm?

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Monday, February 25, 2019 11:08 AM
  • If this control is not installed in Windows through RegSvr32.exe - you will receive a kind of "Some controls which are used are not installed" message. 

    I want to know how to check that it is not registered before I get such message.

    Monday, February 25, 2019 11:52 AM
  • Hi Vitalii P,

    I'm not sure I can understand your description.
    I assume DateTimePicker(s) is(are) in a worksheet, and have made a sample.
      

    [code]
    Private Sub btn_Check_DTP_Click()
        Dim mySheet As Worksheet
        For Each mySheet In ThisWorkbook.Worksheets
            Dim dtpCount As Integer: dtpCount = 0
            Dim myShape As Shape
            For Each myShape In mySheet.Shapes
                If (Left(myShape.Name, 8) = "DTPicker") Then
                    dtpCount = dtpCount + 1
                End If
            Next
            ' ---
            If (dtpCount = 0) Then
                MsgBox "sheet [ " & mySheet.Name & " ]" & vbLf _
                    & "DateTimePicker Not exists"
            Else
                MsgBox "sheet [ " & mySheet.Name & " ]" & vbLf _
                    & "DateTimePicker Exists" & vbLf _
                    & "count = " & dtpCount
            End If
        Next
    End Sub
    If I misunderstand your intention, please explain further in other words.

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Monday, February 25, 2019 12:04 PM
  • Don't use the control at all, instead use this:

    https://sites.google.com/site/e90e50/calendar-control-class


    Regards, Jan Karel Pieterse|Excel MVP|http://www.jkp-ads.com

    Monday, February 25, 2019 12:04 PM
  • Hi Vitalii P,

    What language do you use for finding if DateTimePicker is registered?  VB.NET, C#, or other?

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Monday, February 25, 2019 12:12 PM
  • Hi Ashidacchi,

    In general, I want to do following (I use it for Excel only):

    1. Check the registration on the Workbook_Open event via VBA;

    2. If not registered - check that mscomct2.ocx file exists, if not - put it to needed folder (depending on 32/64 bit OS)

    3. Run VB Script which will be attached to an excel workbook or use API to register the mscomct2.ocx with regsvr32.

    But by now I stuck on how to check that it is registered...

    Monday, February 25, 2019 1:57 PM
  • Hi Vitalii P,  good morning from Japan,

    (1) Sorry, I can hardly understand the meaning of "registration" or "register".
         Could you explain it with other words?

    (2) Do you want to use/write "VB Script" instead of "VBA"?

    (3) I'm afraid you need to describe WHAT your purpose is, before describing How to do.  I suppose it's better make your object clear, and how to do will follow afterwards.

    Regards,

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Tuesday, February 26, 2019 1:25 AM
  • One way is test if you can create it -

    Dim objDTP As Object
    
    On Error Resume Next
    Set objDTP = CreateObject("MSComCtl2.DTPicker.2")
    MsgBox "DT Picker is registered: " & Not objDTP Is Nothing
    Increasingly the DTP and other ActiveX controls are less likely to be installed, better to use alternatives such as Jan Karel suggested.


    • Marked as answer by Vitalii P Tuesday, February 26, 2019 9:12 AM
    Tuesday, February 26, 2019 9:07 AM
    Moderator
  • Hi Peter,

    Thank you for an idea, I think it should work for me!

    Alternatives are may be used, but in my particular case - I will have to change the whole project from the very beginning to replace the Date Time picker.

    Thank you all for your time!

    Tuesday, February 26, 2019 9:16 AM