Deal With The DataControl At Run Time And Design Time

Deal With The DataControl At Run Time And Design Time

One of the greatest features of data-aware controls is that you simplyconnect them to a DataControl and select the fields you need. You havejust created a database program. It can’t get any easier than that. Theonly problem is that if you share this program, nine times out of 10 itwon’t work. Why? Because the database name and directory structure arehard coded into the DatabaseName field in the DataControl.Hard-coding the database name into the DataControl is a major programmingno-no. Instead, you fill this field at run time. Then, before you can ship(or even send the program out to beta testers), you must remove the databasenames from your controls. Then you add them back during design, and soon. What a headache.I don’t have time for that. I created a nice Sub that does the workfor me. Before I give it to you, I need to review a few idiosyncrasiesof loading a DataConrol. With my method, you leave the original databasenames in the DataControl. The problem with this is that as soon as a formloads, it initializes the DataControl. It tries to load the database andrecord set and causes an error. To prevent this, set the Enabled propertyof the DataControl to false. Use this code in each form that uses a DataConrol:

 Private Sub Form_Initialize()	SetDataDBName frmIn:=ME, sDBName:="C:MYPROGDATAMYDB.MDB"End Sub'Calls the following Sub:Public Sub SetDataDBName(frmIn As Form, sDBName As String)	Dim I As Integer	'On Error needed to prevent problems	'with refreshing bad values in the 	'RecordSource property	On Error Resume Next	'Search through form's controls	For I = 0 To frmIn.Controls.Count - 1		'See if the control is a datacontrol			If TypeOf frmIn.Controls(I) Is Data Then			frmIn.Controls(I).DatabaseName = sDBName			frmIn.Controls(I).Enabled = True		'Refresh if there is something 		'in the recordsource property			If Len(frmIn.Controls(I).RecordSource) _				> 0 Then				frmIn.Controls(I).Refresh			End If		End If	Next IEnd Sub

That’s it, easy and painless!

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes