Link to home
Start Free TrialLog in
Avatar of Ryan Bayne
Ryan BayneFlag for United Kingdom of Great Britain and Northern Ireland

asked on

DataField list is empty

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?

Ryan
Avatar of apptsolu
apptsolu

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
  Next


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.

Regards
Avatar of Ryan Bayne

ASKER

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! :-)
ASKER CERTIFIED SOLUTION
Avatar of apptsolu
apptsolu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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

Regards
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,

Leon