Retreiving Field Data

MikeEller

Registered User.
Local time
Today, 15:28
Joined
Jan 7, 2005
Messages
32
Hello,

Been awhile since I have used ACCESS.

How can I, using code, retreive data from specific fields in a table and read that data into a variable? Can this be done?

Any and all assistance is greatly appreciated.

Mike
 
You can use a recordset to "query" a table, then add the values from this to variables or an array depending on what your requirements are. Before you get any code samples, you will need to be more specific on what it is you want to do exactly. In plain english it works like this;

1. Get [Some fields] from [Some table/query]
2. Put [these fields] into [this array/these variables]

In VBA there will be a few lines more, but not a great deal.
 
OK,

What I am doing (attempting) is this.
I have a table with 3 fields that contain text.

I have a button on a form that when clicked, I want to (using code)
to iterate over each field in each record and read the text data into
variable arrays.

Something like this:

For i equals 0 to numberOfRecords
For j equals 0 to 3
field1Array equals read field1Data
field2Array equals read field2Data
field3Array equals read field3Data


This is a rough, down and dirty depiction of what I am doing. It is simple enough to code....I just don't know how to get at the individual field data via code.

Thanks,
Mike
 
I'm still not sure exactly what you want to do here, from what you have said, you can just make a form and set the text box fields to the fields in your table??? A form wizard should do it.

But assuming I've missed something, if you really want to get into recordsets, then here is how I would do it (not declaring all the variables, if you find coding simple, you won't need me to tell you how to do that ;-)...

Code:
rsMyRecordSet.Open "SELECT * FROM tblTable", CurrentProject.Connection, adOpenStatic, AdLockReadOnly
intTotalRecs = rsMyRecordSet.RecordCount
ReDim myArray(intTotalRecs)
i = 1
Do While rsMyRecordSet.EOF
  myArray(i) = rsMyRecordSet(0)
  rsMyRecordSet.MoveNext
  i = i + 1
Loop

rsMyRecordSet.Close

Down and dirty, but that should get you started. If you get stuck, do please post back. Obviously you may need to tweak the SQL statement/array to suit your needs.
 

Users who are viewing this thread

Back
Top Bottom