Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing field data values in VB Script

Status
Not open for further replies.

SteveMillman

Programmer
Jun 3, 2001
36
US
We are trying to access the Values of a table we are processing in a VB script.

The application is to build an access report that we can email... and where are stuck is accessing the contents of
fields on the table.

For example, one field on one table contains the name of the report we want access to run... and another contains the email address we want the report sent to.

There are a few dozen records on the table that comes out of our query, and these are the records we are trying to dynamically build reports and emails (with attachments) from.

How can we access the values of these fields?

We tried using "table name.field name" but ended up with the value of the field name instead of the field contents.

How do you do it?

In running a class object we try to supply the name for our report in its variable .ReportName by pointing it to the value in our Services table, ReportObjectName field as follows: .Reportname = ("Services.ReportObjectName")

This is does not work.

Thanks for your help,

Steve Millman



 
You could try using a recordset. The code would look something like this;

' *** Start Code ***
Dim db As Database
Dim rs As Recordset
Dim strSQL as String

strSQL = "An SQL statement that pulls the data you want"

Set db = CurrentDB()
Set rs = db.OpenRecordset(strSQL)
' in here you can access the value of fields in your
' recordset using the structure
' [variable or report field] = rs("field name")
Set rs = Nothing
Set db = Nothing
' *** End Code ***
There are some variations you can use with the db.OpenRecordset statement, I typically use a SQL string but you can also use a table or query name, I would say check the Help Action topic to determine what would work the best for you.
Another trick may be to determine what Event you should tie the code to, when I have done stuff like this I usually use a form to call the report and run the code on the OnClick event for a button that generates the report. If there are a large set of reports you are generating you would probably want to build a stand alone module to run.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top