DataField list is empty

Posted on 2005-02-26
Medium Priority
Last Modified: 2013-12-25
I'm started my database from scratch. I've created the database file and saved some entrys. I'm creating my form with the ADO control. The connectionstring is complete, tested and is fine. I've put the record source in also. Now...

I've put the first text box on the form and selected the DataSource which holds 1 selection. I then select the DataField list but it is empty. I'm only just learning database and I think that there should be 3 options to choose in the Datafield because there are 3 different types of data in my database. Why is it empty?

Question by:Ryan Bayne
  • 3
  • 2

Expert Comment

ID: 13416518
Hi there,
Just like you I started with ado control and I was advised on this site to use hard code instead of controls, and I have never looked back because it has helped me understand VB in greater detail, plus this way allows (in my opinion) greater flexibility, especially if more than text is needed at a later date, or you need to filter records.
 here is an example of a coded ADO DATABASE  connection to a ms access database, it asks, with the use of * to get all the fields and fill the textboxes with data.

On your form create a text box and name it txtfields, then copy it and paste when asked if you wish to make an array, answer yes it will then go in sequence i.e txtfields(0), txtfields(1), etc.
In the proporties window on the form in datafield set it to the database field, you will have to write this in.

If you dont want to use this method let me know and I will help with the ADODC control, but personally I think if you get used to writing code you understand connections, datatypes and how they can be manipulated.

Dim WithEvents ADOprimaryRS As Recordset ' paste this as the first line in the code (it allows single name reference which I will explain later)

Dim db As Connection ' this bit goes in the form load section
dim ADOprimaryrs as recordset
  Set db = New Connection
  db.CursorLocation = adUseClient
  db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\your database file with extension ;"

  Set ADOprimaryRS = New Recordset
        ADOprimaryRS.Open "select * from tblclient ", db, adOpenStatic, adLockOptimistic ' this 'opens the records

  Dim oText As TextBox
  'Bind the text boxes to the data provider
  For Each oText In Me.txtFields
    Set oText.DataSource = ADOprimaryRS

end sub

another useful hint is to use the wizard to create your form, when asked use ado code and have a look at the way it is constructed.


Author Comment

by:Ryan Bayne
ID: 13417116
I'd like to learn both ways however this is study. I know its not a done thing on here to answer homework but this not being the actuall question I'm sure its not a problem.

I do need to create a database using ADO. Well I've actually created one allready with the datareports and command buttons on the form to add and and delete entrys however the data control on the form was as if it were disabled. After 3 attempts from scratch I ended up with the same problem so this is me starting from scratch.

The point I'm at just now is probably the issue I'm carying forward to the completion of the application.

Funny that, I have a complete working example sent by tutor to copy also...still cant complete my own from scratch. The working example is bases on a different database but the form and datareport are all the same.
Never managed that one before! :-)

ADODC control for now is much appreciated.

Never managed that one before! :-)

Accepted Solution

apptsolu earned 2000 total points
ID: 13418149
Ok. Here goes.
Add ado control to the form and enter the proporties dialog box.
Enter the provider, i.e the type of connection to the database.
for ms access i use jet4, if you have mdac installed on the pc.
foxpro databases typically use isam.

click connection tab and go to the database itself, with any passwords or login details required.
click test and if test succeeded  click ok

under recordsource we can either use a stored procedure such as a query or tablename, in which case click command type and select adcmdtable, then select the table or query used to select the recordsource.
If like me you prefer sql based recordset selectors, keep adcmdunknown  and in the sql section type something like "select * from tblname" (without speech makrks)
this connection is now done.

add a text box to the form and in the proporties window set the datasource to the only one listed i.e adodc1 (or name you have given it)

then under datafield in the proporties window select the name of the field you wish to link the textbox to.

If there are multiple fields see my first response about txtfields and create an array and set each one individually to the datafield required.

let me know how you get on.

if still no joy then we need to look closer to the version of drivers you are using to the type of connection to the database.

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 29

Expert Comment

ID: 13422932
Learning ADODC for school is fine, however if I saw you using it at work in an actual application, you would be fired so fast, you'd leave skid marks.

Expert Comment

ID: 13425058
wo! leonstryker

whilst I might agree with the sentiment, lets keep it positive please.

We are ALL together on this and to be fair its a learning curve. Lets face it who are we to argue with a corporate body who included adodc intrinsic controls in the first place.

TycoonMillion, lets us know how u get on, we are ALL here to help and assist as best WE can

LVL 29

Expert Comment

ID: 13429480
Sometimes the best method of getting something across is shock therapy.  ADODC is one of the most bug prone, unstable, inflexiable controls that was ever created.  It was created as a "teaching" tool at best, although I would not use it even for that.  Its things like this which give VB a bad name.

TycoonMillion if choose not to use ADODC I will be more than happy to help,


Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question