tags:

views:

368

answers:

2

I have an Access form where each record has some info that is computed on the fly. I'm using the Form_Current() event; each time a record is selected, I compute some information and change some form controls to reflect it, based on the record's ID.

I want to print a bunch of these records. However, in this situation the Form_Current() event isn't being triggered and the printed records lack that dynamic information.

Any ideas?

+3  A: 

Make a query that computes the information you need as the source of your report. You can use vba functions if needed for complex calculations.

pro3carp3
Thanks, that sounds good. I read through the documentation but I couldn't figure out how to call VBA from an SQL query though. Any hints?
Luís Oliveira
Create a function in a module and reference it in the SQL. Here is an example I use to convert from a proprietary date format. The name of the function is fdConvertTAMDate. This is what it looks like in the query design window:TranDate: IIf(IsNull([DATE]),Null,fdConvertTAMDate([DATE]))
pro3carp3
Thanks that worked nicely. My function was in the Form itself, which is why I couldn't call it from the SQL query, I suppose?
Luís Oliveira
A: 

In a comment, Luis Oliveira asked:

My function was in the Form itself, which is why I couldn't call it from the SQL query, I suppose?

By default, functions in a form are private. If made public they can only be called when the form is open, as in Forms!MyForm.PublicFunction(). I would advise against that. Instead, move the function to a public module (which may require revisions to remove references to form controls/fields).

David-W-Fenton