Author: Mike Shkolnik
How I can open a report (in Print Preview mode and also print direct) in an MS
Access database?
Answer:
In the next small example I'll demonstrate how you can call the report in MS
Access:
1 2 var3 Access: Variant;
4 begin5 // open the Access application6 try7 Access := GetActiveOleObject('Access.Application');
8 except9 Access := CreateOleObject('Access.Application');
10 end;
11 Access.Visible := True;
12 13 // open the database14 //The second parameter specifies whether you want to open the database in 15 Exclusive mode
16 17 Access.OpenCurrentDatabase('C:\My Documents\Books.mdb', True);
18 19 // open the report20 {The value for the second parameter should be one of21 acViewDesign, acViewNormal, or acViewPreview. acViewNormal, which is the default, 22 prints the report immediately. If you are not using the type library, you can 23 define these values like this:24 25 const26 acViewNormal = $00000000;27 acViewDesign = $00000001;28 acViewPreview = $00000002;29 30 The third parameter is for the name of a query in the current31 database.The fourth parameter is for a SQL WHERE clause - the string must be valid32 SQL, minus the WHERE.}33 34 Access.DoCmd.OpenReport('Titles by Author', acViewPreview,
35 EmptyParam, EmptyParam);
36 37 { ... }38 // close the database39 Access.CloseCurrentDatabase;
40 41 // close the Access application42 {const43 acQuitPrompt = $00000000;44 acQuitSaveAll = $00000001;45 acQuitSaveNone = $00000002;}46 Access.Quit(acQuitSaveAll);
47 end;