Library tutorials & articles
Data Control
Viewing a simple database
I will now take you through the few basic steps required to create a program that will show you records in an Access database. We will then eventually expand this program, to provide support for adding & deleting records, and searching etc.
Firstly, create a new project, and add a DataControl to the form. It looks
like this: .
Set its name property to datTitles, and its Text property to Titles.
Next, you can click the ... (3 periods) next to the DatabaseName property. A browse dialog will be shown. An example Access database, which we will use, called Biblio.mdb is provided with VB, and should be located in the same folder that VB was installed in. If you can't find it, you can download it here. Before proceeding, I recommend you save a copy of it and name it Biblio_original.mdb, so that if you make any changes you don't like you can restore the original database without having to reinstall VB, or search around on the CD.
Once you have located the file, select it, and click open. This has specified the database where the control will get its information from.
Now you need to select the table you want the control to get the fields from - click the arrow next to the RecordSource property, and select Titles
These are the basic steps in using the Data Control. Next, you need to add some labels and text boxes that will show the contents of each field. In order to do this, you need to bind them to the Data control, by setting each of the text boxes DataSource property to datTitles (the DataControl), and setting its DataField property to the field you want it to display. You can also add labels next to each text box so that the user knows what field each textbox is linked to. Add the following text boxes:
| Name | DataSource | DataField |
| txtTitle | datTitles | Title |
| txtYearPublished | datTitles | Year Published |
| txtISBN | datTitles | ISBN |
| txtPubID | datTitles | PubID |
| txtDescription | datTitles | Description |
Now, save and run your project. Try clicking each of the arrows on the DataControl. You will see, that the control loops through each record in the table, and updates the text in all of the bound text boxes. All without you writing a single line of code!
Related articles
Related discussion
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
-
Can you describe Above simple VB6 code?
by pramodmca09 (0 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Hi ! All,
I'm new in VB Programming and trying with all your given examples. I'm trying to create a database project. I've created a table in Access 2000 and wants to attatch it with my VB Project. But whenever I run the Project it displays the following error message:
Runtime Error # 3343
Unrecognized Database Format
Please tell me what to do now.
Thanks & Best Regards
From
Bhasker Kumar
Email :- bhaskerno123@yahoo.co.in
im a newbie in vb, im working now with the examples above, my objective is to save,add, delete files to the database i can't do it. there is a propmted error invalid or unqualified references.
i am a newbie in vb,and now im currently working with the tutorials that are post above, my objective is that i want to save, add or delete a file to my stand-alone database. thanks for fast replies.
At least give some explanation about the environment or
what is you objective.
hi there, why is that i can't add or save new file? the error propmt is
"invalid or unqualified reference." plz send me an answer or email it to me plz..hoping to hear from you. ASAP..thanks
The download link doesn't work...
I am currently having problems searching a dbase3 file using the data control. Can anyone offer any suggestions as to searching? I am using bound controls (testboxes) to display the data. I can use the directional buttons to move forward and back but I cannot search for a specific value.
Thanx in Advance
is it the recordsource or what?
it's good control
This thread is for discussions of Data Control.