Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB6
Expertise: beginner
Jan 22, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Change the DataSource at runtime

Visual Basic 6 is the first VB version that lets you programmatically change the DataSource property at runtime, for example to point to another ADO Data control or another ADO Recordset.

However, when you assign the new DataSource property VB immediately checks that the DataField and DataMember properties are valid. This means, for example, that if the new data source doesn't expose a field with the same name as the current value of the DataField property, you get error Error 545 - Unable to bind to field or DataMember: 'fieldname'.

Fortunately, you can work around this problem by simply setting the FieldName property to a null string before setting the DataSource property, and then assign it the new value:

' have Text1 point to another Data control
Text1.DataField = ""
Set Text1.DataSource = Adodc2
Text1.DataField = "City"
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date