vba - Populating reports with calculated values -


i hope simple question , don't have waste of time on it. have report (called reprad78) contains textbox (called txtrad8). populate txtrad8 calculated value based on numbers pulled query called qryrrad78. looking through forums looks recordsets solution first foray recordsets , it's not going well. :( code have pasted in below have pulled number of places , doesn't produce errors puts same value txtrad8 records. i'm sorry if stupid question it's been driving me potty. many time. al.

public sub calc()  dim dbs dao.database dim rst dao.recordset set dbs = currentdb set rst = dbs.openrecordset("qryrrad78") rst.movefirst until rst.eof = true   dim lngmean long dim lngrad78max long dim lngrad78_1 long dim lngrad78_2 long dim lngrad78_3 long dim lngrad7 long dim lngrad8 long  lngrad78_1 = rst![rad78_1] lngrad78_2 = rst![rad78_2] lngrad78_3 = rst![rad78_3] lngrad8b_c = rst![rad8b_c]  lngmean = (lngrad78_1 + lngrad78_2 + lngrad78_3) / 3  lngrad78max = maximum(abs(lngrad78_1), abs(lngrad78_2), abs(lngrad78_3))  lngrad7 = ((lngrad78max - lngmean) / lngmean) * 100  lngrad8 = ((lngmean - lngrad8b_c) / lngrad8b_c) * 100  txtrad8.value = lngrad8   rst.movenext loop  rst.close dbs.close  end sub  private sub detail_format(cancel integer, formatcount integer) calc end sub 

here's second approach this. rather using function in code, take calculations calc() routine , put them in query.

select idrrad78,     (rad78_1 + rad78_2 + rad78_3) mean,     (iif(abs(rad78_1) > abs(rad78_2),         iif(abs(rad78_1) > abs(rad78_3), rad78_1, rad78_3),         iif(abs(rad78_2) > abs(rad78_3), rad78_2, rad78_3))) rad78max,     (((rad78max - mean) / mean) * 100) rad7,     (((mean - rad8b_c) / rad8b_c) * 100) rad8 qryrrad78 

this give query performs same calculations existing function. edit report query join new query (just joining table) using like:

from reportquery inner join newquery on reportquery.idrrad78 = newquery.idrrad78 

change query names match real names. add fields new query in select part of report query:

select <existing field list>, rad7, rad8 

then set txtrad8 rad8 field.

i'm doing memory i'm not in front of own computer, makes sense , close enough correct code.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -