Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I create an ActiveX UserControl for MS Access

Status
Not open for further replies.

darkangrydragon

IS-IT--Management
Jul 18, 2002
15
0
0
US
Hi everybody!

I know how to create ActiveX UserControls and DLL's. But my question is, how do you create an ActiveX UserControl that can be bound to a field in Microsoft Access?

For example, say I create an ActiveX UserControl project in VB 6. I draw a text box on the control, Text1.

What code/settings need to be added so that when I drop the compiled OCX into an Access form, I can link it to a field from the form's recordsource via the control's Control Source property, so that the contents of the field display in the Text1 text box?

Phew! I hope that makes sense.... :)

Thanks!
-Andrew
 
Andrew,

Did you ever got an answer on this question, because i want to contruct a control that does the same.

Thanks in advance....

Jan de Graaf
 
Basically, the technique for getting constituent controls (such as your Text1 example) to behave as they would outside of a UserControl container is to expose their state as properties of the UserControl. A very simple example of this would be to have a txtUserID and txtPassword text box on a UserControl. To allow a container of the usercontrol (such as a form) to access the values in these two text boxes, just create two readonly properties of the usercontrol, called, say, UserID and Password, and expose the Text properties of the text boxes through them:
Code:
Public Property Get UserID() as String
UserID = txtUserID.Text
End Property

Public Property Get Password() As String
Password = txtPassword.Text
End Property
Notice that it's unnecessary to store the current value of the property in a private variable as is typical, since the current value is whatever's in the Text Box.

Now, you can do this with any properties that you like, as well as methods and events (events are a little more complicated). As for showing the contents of a field, just make the property writeable (create a property Let proc) and set it whenever appropriate through code.

HTH

Bob
 
I know how to pass values to and get values from user controls with the get en let procedures.

But i want a control that behaves as a standard user control in ms access xp.

So that i can bind datefields of tables to the control for input just as the textboxes etc in access self.

to quote the first post: Makes sence?

Jan
 
You are looking for a "Data Consumer". If you look at the options you have when you add a class to a project, you will see there is an option for a "Complex Data Consumer". If you add a "Data Consumer" class to your ActiveX control you will be able to bind it to your Access data. It will not be all Wizards and Go but you may want to take a look at Planet Source Code, The Code Project or MSDN. They all have examples of code to creating a data consumer class.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Yes, I avoid the use of the Data Consumer/Data Provider. IMO, adding another level of marginally-documented complexity to data binding which is a bad horse to begin with strikes me as not the best of ideas. I would handle the binding myself with ADO objects, which can be done by writing your own methods and properties of your user control.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top