Creating Custom ActiveX Controls
I repeatedly need to use a Common Dialog Box for Opening and saving files. And most of the time I require to show a textBox containing the filename and a browse button which opens the dialog. It would have been better if I had a single control taking care of the dialog, textBox and the Button. If it doesn't exist why not create one?
Create a new VB Project of type "ActiveX Control". Open the Project Properties and give the Project Name as "MyCustomControl" and Project Description as "My Custom Dialogs Control".
Name the default user control as OpenFile. Change the Appearance Property of the control to "0 - Flat" and backStyle to "0 - Transparent". Use the ToolboxBitmap property to assign a picture representation to the control which will be visible on the Toolbox.
Place a textBox txtFileName and a button cmdOpen and a "Microsoft Common Dialog Control 6.0" dlgOpen. Change the size of the control so that it's just enough to carry all the controls. Keep the surrounding borders to minimum.

Place the code below
Public FileName As String
Private Sub cmdOpen_Click()
dlgOpen.ShowOpen
txtFileName = dlgOpen.FileName
End Sub
Private Sub txtFileName_Change()
Me.FileName = txtFileName
End Sub
Public declaration "FileName" creates a custom property for the control which can be accessed by the parent application.
While cmdOpen_Click() opens the dialog box and changes the textBox as per the fileName returned by the Dialog, txtFileName_Change() ensures that anytime the text is changed, be it due to dialogBox or due to manual changes to the textbox, the property FileName of the control is updated.
Generate the OCX file. This is just a minimal control which, you can add this control to your applications. More on this subject will be taken later.


