Link the DataField to the Recordset

The data control allows you to quickly link controls and databases; however, not only is it far from flexible compared with the database-objects coding interface, it doesn’t look great. I use the latter solution and assume most VB programmers do. But it’s quite painful to add or alter several lines of code every time you put a new text field on a dialog. It’s a waste of the DataField property, however; it can be just as useful as the Tag property, and in this case, it’s more descriptive. So what if you write a few routines to simulate the data control’s basic operations through the DataField property? This simple routine loads data from a Recordset to all controls on a form:

 Public Sub ReadData(frm As Form, rc as Recordset)	Dim ctrl As Control	' Need to ignore errors on controls	' that don't support databinding.	On Error Resume Next	For Each ctrl In frm.Controls		If ctrl.DataField <> "" Then			ctrl = rc.Fields(ctrl.DataField)		End If	Next 'ctrlEnd Sub

You only need to put the field name into the DataField property of involved controls at design time. By altering such routines, you can achieve more complex data handling than if you use data controls, as well as make reading, writing, and validation a lot simpler than doing everything manually.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS