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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get data from table into a form?

Status
Not open for further replies.

DJKAOS

Technical User
Jun 30, 2000
101
US
Hi, I have a Report and text boxes on it, I can get the stuff in the textbox if I use access built in expression builder...

but how can I get it using vb code?

Lets say my text box is named TextBox and its in my report, which gets data from Table->Main

How to I set
TextBox = Table->Main->FirstName

SO basicaly How do I get the first name of the current record put into the text box using VB code instead of the expression builder.(can't use it for some because I need to
access the data in some fileds that I didn't make text boxes for.)

Thanks
 
Well you said that the Report is getting data from the table Main. This means that the text box Control Source drop down will have all of fields for the table available to be selected.

You see a report is bound to a table or a query. All of the fields in each are then available to be displayed by simply selecting that field from the list. Open up the properties of the Text box and in the Control Source property click the down arrow and then pick the field name FirstName. It is not necessary to use VBA code on a report that has the table as the recordsource.

If this doesn't answer your question please respod back with more information. I may be a little confused because the question title refers to data in a form but the question itself refers to a report. Please be specific as to exactly what you want.

Bob Scriver
 
Sorry, what I made up that example its not really what I'm doing...but I thought I would simplify my question.

Ok On my Report I need to do a calculation on some things.
ANd I absolutly hate using the expression builder its so hard to read my formulas because some of them are VERY long...(Some wont even fit in the expression builder because they are to long.)

SO I basically have to use VB Code...
I need for example TextBox01 on my report to show the value of a complex function made from fields from the table.

I tried Me.[Field Name] that didnt work
I tried Forms!Main.[FieldName]

What I want it something like this in my report
Dim Temp as Variant
Temp = Some crazy function that pulls values from the Main Table.

Its just a refrencing problem...I dont know how to do it in vb.
 
Sorry, what I made up that example its not really what I'm doing...but I thought I would simplify my question.

Ok On my Report I need to do a calculation on some things.
ANd I absolutly hate using the expression builder its so hard to read my formulas because some of them are VERY long...(Some wont even fit in the expression builder because they are to long.)

SO I basically have to use VB Code...
I need for example TextBox01 on my report to show the value of a complex function made from fields from the table.

I tried Me.[Field Name] that didnt work
I tried Talbes!Main.[FieldName]

What I want it something like this in my report
Dim Temp as Variant
Temp = Some crazy function that pulls values from the Main Table.

Its just a refrencing problem...I dont know how to do it in vb.
 
Okay let's start at the beginning. To reference any of the data from the table you have to have a text box that is bound to that item. If the data is such that you do not want to print the data then set the textbox visible property to NO. You can also make it very thing, delete the corresponding label, and set it over to one side and out of the way in the Detail Section. Now you can reference that textbox in code. The table data must first be referenced in the Report by creating a control that brings the data to the report in a format that you can then write the code referencing it.

i.e.
vVariable = (me![Textbox1] / me![Textbox2]) * me![Textbox3]


This code can be put in the OnFormat property of the Detail Section. It will execute prior to formatting each detail records line. This is where you would put all of this VBA code to create new values to display.

You can also set the control Source property of a particular textbox to any number of functions(DLookup, DCount, DSum, etc)

Now, you had better get used to using the expression builder to perform even complex expressions. The reason for this is that you can create queries that can be used as the RecordSource for a report and most of the equations are done before you are ready to print.

We can help with these type of equations if you wish. You see the queries which can include multiple tables linked together by common fields that are releated can then be fashioned to perform even complex equations and have the data ready for printing. It is much easier to do it that way then with VBA code in the report sections event procedures. There is a place for both but don't give up on the Expression Builder process.

I hope this helps you understand the process.

Bob Scriver
 
Yes thank you...thats how I used to have it..
I just didn't want to create about 20 invisible text boxes..I was looking for another way.

The first time I made this database I only used the expression builder.

now I'm using a lot of VB.

anyway Thanks I can make it work with invisible textboxes.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top