How to specify the connection string of an ADODC control at runtime.

I want an ADODC which has to connect to a different location(database,username and password).

Now when i specify the connection string at design time the databinding of the other controls seem to work fine. Now when i remove the connectionstring from the design time settings and then set the connection string of the ADODC control at run-time, the ADODC gives an error of 'Object Required' when any reference to the underlying recordset is made.

It will be great if someone has a solution for the same.
Many thanks in advance as it is a matter of urgency.
Who is Participating?
ventondConnect With a Mentor Commented:
If you change a data controls connection string at run time (after it has already opened), you must tell the data control to reconnect. (Re Open). Or, better solution, don't have it set in design time at all.

Set it in design time, use the retrieve fields of your other controls, then unset it. That way the data control will never have established the first connection string before you change it, and you won't have to Re-open the control.

I am not sure but it seems that your controls are trying to initialize before your suppling the connection string.  You could try to give your app the connection string sooner in your code like in the form initialize event perhaps.

Can you show us the code in which you are removing and settings the connection string?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

May be you need to set the connection string in form_load and set it to your control. ^_^

good luck.
Anthony PerkinsCommented:
Actually you need to set it before you Show the form.  In other words make Main() in a .bas module the startup object and initialize the Data Control to the connection string here, than do a Refresh and finally Show the form.

Having said this, you may want to re-consider using the Data Control in the first place as they are typically more trouble than they are worth.  Most developers use them once in a major app and never again.


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to Glowman
Please leave any comments here within the
next seven days.
john_vimalAuthor Commented:
thanks for your help mate
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.