?
Solved

DataField list is empty

Posted on 2005-02-26
6
Medium Priority
?
335 Views
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?

Ryan
0
Comment
Question by:Ryan Bayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:apptsolu
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
  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
0
 
LVL 2

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! :-)
0
 
LVL 2

Accepted Solution

by:
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.

Regards
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Expert Comment

by:leonstryker
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.
0
 
LVL 2

Expert Comment

by:apptsolu
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

Regards
0
 
LVL 29

Expert Comment

by:leonstryker
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,

Leon
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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, 18 hours left to enroll

764 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