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

Currently used table... 1

Status
Not open for further replies.

SeadnaS

Programmer
May 30, 2011
214
0
0
Hi,

I've just converted a macro I was using to VBA and I want a formula on it to be able to work on the table currently opened by the form (the record source).

I've got a button to click that calculates the average but it only calculates the average of Table1:

Average = DAvg("numbers", "Table1")

Now i want this to work on whatever table it is that is open by my form is there something that I can replace "Table1" with like "CurrentTable" or "OpenTable" or "RecordSource" something like that? I have a few different tables and they all have the field "numbers". Bear in mind im a beginner!

Thanks!
 
Hi,

It would help if you identified how your open form selects the different table(s). Is this from another button, a combo box (drop-down list) or what? To get the required average could be straightforward; the action of selecting the table just needs to run some code to 'plug in' the table name and field name into your formula.
 
I have a combo box that lists the tables and selecting a table from the combo box changes the forms record source to that table.

Thanks.
 
if in your combobox you have the table name then

change to
Code:
Average = DAvg("numbers", Me.CmboBoxName)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top