Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Passing frame object in code

Hi,

Tim, thanks for your help. I corrected the code as you said plus added
a bit more as I found out the me.activecontrol is actually the frame
not the Combobox
which is pressed.
Therefor i used me.activecontrol.activecontrol.value.

JLG, if you take a close look a the code, then the if statement should
make senese as I want to set diffenrent properties of the combobox if
the value selected from the list is "yes" or not.

Here is the final code which I can use in all my userform with regards
to the controls in the frames.


Sub ComboBox_6_Rental_RQ_dropbuttonclick()
Call ActivateFields(4)
End Sub

Sub ActivateFields(FormNumber As Integer)

Dim MyForm As UserForm
Dim ActiveFrame As Control
Dim Ctrl As Control
Dim ActiveControlName As String

Set MyForm = UserForms(FormNumber)
'First activecontrol has focus on frame
Set ActiveFrame = MyForm.ActiveControl

'Next activecontrol has focus on selected combobox
ActiveControlName = MyForm.ActiveControl.ActiveControl.Name

'If TypeName(Ctrl) < "ComboBox" Or TypeName(Ctrl) < "TextBox" Then
'Exit Sub
'End If


If MyForm.ActiveControl.ActiveControl.Value = "Yes" Then

For Each Ctrl In ActiveFrame.Controls
If (TypeName(Ctrl) = "ComboBox" Or TypeName(Ctrl) =
"TextBox") And Ctrl.Name < ActiveControlName Then
Ctrl.Enabled = True
Ctrl.BackColor = RGB(255, 255, 255)
End If
Next
Else

For Each Ctrl In ActiveFrame.Controls
If (TypeName(Ctrl) = "ComboBox" Or TypeName(Ctrl) = "TextBox")
And Ctrl.Name < ActiveControlName Then
Ctrl.Enabled = True
Ctrl.BackColor = RGB(150, 150, 150)
End If
Next

End If

End Sub

Thanks again Tim.

Best regards

Marc Bruun


On 15 Jan., 04:55, "Tim Zych" <tzych@NOSp@mE@RTHLINKDOTNET wrote:
The concept is sound, but remove the form reference from the frame & control
variables:

* *For Each Ctrl In Me.ActiveFrame.Controls
* * * *If TypeName(Ctrl) = "ComboBox" Or TypeName(Ctrl) = "TextBox"
Then
* * * * * *Me.ActiveFrame.Ctrl.Enabled = True
* * * * * *Me.ActiveFrame.Ctrl.BackColor = RGB(150, 150, 150)
* * * *End If
* *Next


should be:

For Each Ctrl In ActiveFrame.Controls
* * If TypeName(Ctrl) = "ComboBox" Or TypeName(Ctrl) = "TextBox" Then
* * * * *Ctrl.Enabled = True
* * * * *Ctrl.BackColor = RGB(150, 150, 150)
* * End If
*Next

If Me.ActiveControl = "Yes" Then


Assuming you mean ActiveControl.Caption ? That line didn't work.

--
Tim Zych
SF, CA

"Marc" wrote in message

...



Hi,


I have a problem with the code below.
I cant understand why Im not allowed to pass on the frame object for
later use in the code.
I am using this because I have several comboboxes in different frames
that should use the same code.


Sub ComboBox_6_Rental_RQ_DropButtonClick()
Dim ActiveFrame As Control
Dim Ctrl As Control


Set ActiveFrame = Me.Frame_6_Rental


If Me.ActiveControl = "Yes" Then


* *For Each Ctrl In Me.ActiveFrame.Controls
* * * * * *If TypeName(Ctrl) = "ComboBox" Or TypeName(Ctrl) =
"TextBox" Then
* * * * * * * *Me.ActiveFrame.Ctrl.Enabled = True
* * * * * * * *Me.ActiveFrame.Ctrl.BackColor = RGB(255, 255, 255)
* * * * * *End If
* *Next
Else


* *For Each Ctrl In Me.ActiveFrame.Controls
* * * *If TypeName(Ctrl) = "ComboBox" Or TypeName(Ctrl) = "TextBox"
Then
* * * * * *Me.ActiveFrame.Ctrl.Enabled = True
* * * * * *Me.ActiveFrame.Ctrl.BackColor = RGB(150, 150, 150)
* * * *End If
* *Next


End If


End Sub


Hope you can help me.


Cheers


Marc- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object instead of passing arguments Arne Hegefors Excel Programming 1 November 9th 07 12:23 PM
Passing a TextBox Object clara Excel Programming 1 May 7th 07 09:29 PM
Passing collections to an object Art Excel Programming 4 March 15th 07 06:27 AM
passing an object mark Excel Programming 2 May 22nd 06 04:37 PM
How can I make an excel cell equal to the value of a frame object text box directionalman Excel Worksheet Functions 1 February 27th 06 09:24 PM


All times are GMT +1. The time now is 11:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"