Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Type Mismatch with Set instruction

    I'm wanting to use this to get the caption of the current Frame item
    Code:
    Dim C As MSForms.Control
      Set C = Me.ActiveControl
      If TypeOf C Is MSForms.Frame Then Set C = C.ActiveControl
      Me.Tag = C.Caption
    But it's not the active control. It's a frame called "frmSheet" I've tried various combinations but all result in Type Mismatch error.


    What would be the correct syntax for Set C= Me.frmSheet

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Forgetting any code changes to that for the moment, what is the "caption of the current frame item"?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Does the text matter ? I'm still to finalise that. The Frame contains 5 radio buttons with captions and one will (always) be selected

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    It matters if I don't understand the statement. AFAIK, an option group can only accept numbers, so there's that.
    Or maybe you want the caption of the label. Or maybe the name of the control that is selected. So if option buttons in a group can't use text for values, then I have no idea what the caption thing is all about.

    The only way I know of to determine which option in a group is selected is to compare the frame value to the known option value, which is an indirect method but should work. Once you know the selected option control you can get the label caption if that's what you're looking for.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Can you post a graphic of the "frame" involved? And provide more detail on the Caption you are trying to identify and record in the form's Tag property. Maybe tell us why you are doing this for context.

  6. #6
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Sure, image attached. The caption text may change but surely no matter
    The problem line is Set C = Me.ActiveControl and the question was how amend that to work with my Frame
    The code is how originally written and found online. I won't be using the Tag.
    Attached Thumbnails Attached Thumbnails Imagef.jpg  

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Seems that the "caption" is the label caption. If the label is attached, consider the likes of
    Code:
    Select Case Frame0
         Case 2
              MsgBox "label caption is " & Me.Option2.Controls(0).Caption
         Case 4
              MsgBox "label caption is " & Me.Option4.Controls(0).Caption
         Case 6
              MsgBox "label caption is " & Me.Option6.Controls(0).Caption
    End Select
    where the option values are 2, 4 and 6
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    For what it's worth (or not), I took a form I had with an OptionGroup

    and some code to print the "option captions".

    Click image for larger version. 

Name:	demoformWithOptionFrame.PNG 
Views:	22 
Size:	16.7 KB 
ID:	49409

    This png shows some of the properties. The options and captions in the optionGroup/Frame are all labels.
    The caption you're seeking seems to be a label caption.
    Click image for larger version. 

Name:	OptionFrameProperty.PNG 
Views:	22 
Size:	22.5 KB 
ID:	49410

    The code:
    Code:
    Private Sub Form_Load()
        Dim c As Control, opt As Control
        For Each c In Me.Controls
    
            If TypeOf c Is Access.OptionGroup Then
                For Each opt In c.Controls
                    If TypeOf opt Is Access.Label Then
                        Debug.Print opt.name & " " & opt.Caption
                    End If
                Next opt
            End If
        Next c
    End Sub
    The result:

    Label5 Dates
    Label8 DateCreated
    Label10 DateModified
    Label12 DateLastAccessed

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @Middlemarch: I see you declare your control as MSForms.Control and use
    Code:
    If TypeOf C Is MSForms.Frame
    . Is this in Excel?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    Thanks all for help and examples, but I must have worded the question badly. I'm already reading the caption with
    Code:
     = Switch(frmSheet = 1, "A", frmSheet = 2, "XP", frmSheet = 3, "LP", frmSheet = 4, "B", frmSheet = 5, "19")
    What I was after was how to see if the instruction Set C = Me.ActiveControd could be modified towork (for my Framel), or not. @Gici the code in Msg1 was shown as for Access (not Excel) and found on Google.


  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    But it is not for Access but for Excel....
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I'm wanting to use this to get the caption of the current Frame item
    I still think the method is as per post 7 except you'd use Case Me.ActiveControl. Not understanding the point of the exercise though, but that's OK.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Quote Originally Posted by Gicu View Post
    But it is not for Access but for Excel....
    Microsoft Forms 2.0 controls are for use in Access as well. See the list of ActiveX controls in the extended toolbox. I have never used them in Access.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I've never used ActiveX controls in a production db but have played with some. Just today tried a Listview, unsatisfactorily. From another Middlemarch thread https://www.accessforums.net/showthread.php?t=87344

    I don't see a MSForms listed in ActiveX controls. I do see Microsoft Forms 2.0 Frame and other controls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    @June: yes, those are the ones, you can qualify them in VBA with MSForms.Frame and so on. Never used them as the Access built-in controls (in this case the option group) were satisfactory for my needs.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Intermittant #Type! type mismatch error.
    By Ranger351w in forum Programming
    Replies: 4
    Last Post: 09-27-2020, 07:53 PM
  2. Type Mismatch
    By Alex Motilal in forum Programming
    Replies: 5
    Last Post: 02-04-2017, 05:57 PM
  3. Type 13 (Type Mismatch) error
    By sdel_nevo in forum Programming
    Replies: 5
    Last Post: 01-22-2016, 10:01 AM
  4. type mismatch
    By seeker63 in forum Programming
    Replies: 2
    Last Post: 12-05-2013, 02:54 PM
  5. Type Mismatch - HELP!
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-17-2009, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums