Assigning a value to a msforms.frame object.

medic5678

Board Regular
Joined
Nov 13, 2018
Messages
67
Hi everyone

I have several frames within a form I'd like change the attributes of depending on the click of a button
so, I have declared an object in module one



Public frametochange As MSForms.Frame


in Form1, I have many frames I'd like to change if a button is clicked.

in the button click event code I have

frametochange = me.frame1 '(or frame2,frame 3, etc, depending on the button that was clicked)


Then I'd like to call a subroutine to manipulate the attributes of the frame


sub displayframe()
frametochange.height = 200
frametochange width = 400
etc.


end sub


I'm getting a "compile error Invalid use of property on the statement on the assignment

frametochange = me.form1.

What am I doing wrong?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You said
I have several frames within a form

Do you mean a Userform or a Worksheet.

 
Upvote 0
If your using a Userform try this:
Code:
Private Sub CommandButton2_Click()
'Modified  11/15/2018  11:33:41 PM  EST
Dim c As Control
    For Each c In Me.Controls
        If TypeName(c) = "Frame" Then
    
            With c
                .Width = 400
                .Height = 200
            End With
        End If
    Next
End Sub
 
Upvote 0
For a start, when working with objects, e.g. frames, you need to use Set.
Code:
Set frametochange = Me.Frame1

By the way, there's no real need for the frametochange variable as you can pass the frames directly to the sub that manipulates them.

For example, you could write the displayframe sub like this.
Code:
Sub displayframe(frm As MSForms.Frame)

    With frm
        .Height = 200
        .Width = 400
     End With

Which you could then call like this.
Code:
displayframe Me.Frame1
 
Last edited:
Upvote 0
2 elegant solutions. Thank you both very much. I used your code, Norie, as it it better with the way I'm doing this project. I fumbled with this half the night.
 
Upvote 0
When I tried Norie's script it only changed the size of Frame1
So to have it change the size of 20 frames you would have to write 20 lines on code.
Unless I'm missing something.
 
Upvote 0
When I tried Norie's script it only changed the size of Frame1
I thought the OP was looking for code to handle an individual frame, not multiple frames.

If they do want to apply the same changes to multiple frames it would be easy enough to set something up to pass them to sub.

For example to change Frames1-20.
Code:
Dim I As Long

    For I = 1 To 20 
        displayframe Me.Controls("Frame" & I)
    Next I
 
Last edited:
Upvote 0
The original post said:
I have several frames within a form I'd like change the attributes of depending on the click of a button

The user was happy with your script so that's all that matters. I'm sure he figured it out. My script loops through all the Frames.
I thought the OP was looking for code to handle an individual frame, not multiple frames.

If they do want to apply the same changes to multiple frames it would be easy enough to set something up to pass them to sub.

For example to change Frames1-20.
Code:
Dim I As Long

    For I = 1 To 20 
        displayframe Me.Controls("Frame" & I)
    Next I
 
Upvote 0
The original post said:
I have several frames within a form I'd like change the attributes of depending on the click of a button

The user was happy with your script so that's all that matters. I'm sure he figured it out. My script loops through all the Frames.

This was my second post and I've been studying VB for about a week. I don't think I made it very clear as to what I needed. You also had an elegant solution.
 
Upvote 0
A second question, for this I do need a loop.

I have 10 checkboxes that I need to set value to FALSE

They are named NACB101 thru NACB110.

for x = 1 to 10
NACB101.value = FALSE (not sure how to concatenate the name of the textbox here so I can increment with a counter).

next x

Thanks for your help here. This is proving to be an awesome resource for actually getting things done.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top