# User Control VB6 ... QUICK HELP NEEDED!!!

## Recommended Posts

Hello... im buildign a user control in VB6. its acutally an icon with diff functions. through a click event on the icon a dialog is opened... my project for the uc consists of a form for the dialog and the actual UC. i would like to access the .Name property of the UC from the codewindow of the dialog. in order to use the .Name of the UC as part of the .Caption of the dialog that pops up... lets say ucPump.Name --> Pump1 in the load form part of the dialog: --> dialog.Caption = "Name of Pumpe" &ucPump.Name ... something like this. im new to VB6 and the tutorials i did didnt provide any info on things like this... so id need some help... THANK YOU

##### Share on other sites
This should basically do what you want. It's been a long time since I've done UserControls in VB6, so there's probably a better solution out there someplace, but this ought to do for starters.

' In the dialog formDim MyControlReference As TheControlPublic Sub SetControl(ByRef ControlReference As TheControl)  MyControlReference = TheControl  Debug.Print MyControlReference.NameEnd Sub' In the UserControlPrivate Sub TheControl_Click()  Dim dialog As TheDialog  dialog = New TheDialog  dialog.SetControl Me.Object  dialog.Show vbModal  dialog = NothingEnd Sub

Basically, the dialog needs to be told what control to "attach" itself to. Once it knows this, it can access it and manipulate it as a normal control. To accomplish this, we simply add a step when we create the dialog, and tell it what control to attach to via our new custom SetControl routine.

Note that SetControl is passed "Me.Object" from the UserControl rather than just Me. This is to ensure that the value given to SetControl is of type TheControl, in case the UserControl is given a default property.

##### Share on other sites
It seems to me as if my problem was understood like:

i got a project... import a working user control and add a dialog-form.
then make them work together...

but im still working on the user control...
and withing my usercontrol-project i got code for the usercontrol part and code for the dialog....
and i want to those to work together... the problem is that i cannot call the ucPump in the code window of the dialog... cause withing the project the usercontrol might not be known yet by ucPump...
maybe...
im not sure. thats an assumption...

How can i make them work together?????

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Forum Statistics

• Total Topics
627707
• Total Posts
2978721

• 21
• 14
• 12
• 22
• 35