Tuesday, February 13, 2007

MS Access and ms word

Consistent use of features and interface has never been a strong point of microsoft products. Some people accuse microsoft of cross selling to create and maintain monopolies, and I understand these accusations.

But I vividly remember that in an old version of ms office, the default directory whem I saved a new word document was the same as with the previous document, while ms excel alsways started in "my documents". As I never use the "my documents" directory for serious documents, but always tend to save important docs in "real" directories, I regretted the excel default. Unfortunately, since then microsoft has tended to standardize on "my documents" even more.

In one of my latest projects, the customer wanted to export reports to ms word. A fellow worker told me this would be no problem. Of course I should have been more careful. I objected and said that I wanted to see a working demo first.

He delivered one in record time.
It turned out he used the code:

DoCmd.OutputTo acOutputReport, "ReportName", acFormatRTF, "report.doc"

It worked beautifully, even with a subreport, and I accepted.

I should have read more closely. The "acFormatRTF" should have warned me. It generates an rtf file, which is saved as a word document. In a way MS Office are wonderful: even when the file extension tells you otherwise, ms word automatically recognize rtf and html.

One problem that arose was the use of page footers. We wanted to have a reportname and pagenumber at the bottom of each page. We added them to the pagefooter of the ms access report. When we exported the report to rtf, it generated plain text on each page. And the page lengths didnt match, so the pagenumber appeared a little bit higher on each page.

We could solve that one by making the pagefooter elements in the report invisible before exporting them. Then we wrote an ms word macro which added page footers.
In ms access:
Reports!Reportname.MyPageFooter.visible = false
DoCmd.OutputTo acOutputReport, "ReportName", acFormatRTF, "report.doc"

A second problem was that we had a lot of memo fields and subreports. Both tend to have variable lengths and a nice border around them. When exporting the reports to rtf, ms access forgot the borders.
But as our customer needed the borders to make the document pretty enough to comply with the standards demanded by their customers, we simply had to add these borders. You can sometimes persuade a customer to be satisfied with something less than he hoped for, but a good customer won't accept no for those products he sends directly to his own customer.

This solution was even more complex than the previous one. On the main report, we added 2 tages for each memofield and subreport: a "startsub" and "endsub", placed before and after each memofield and subreport. These were made invisible before showing in ms access, and made visible before exporting to rtf.
Again an ms word macro had to be written. This one selected all text between and including the two tags, and moved it into a newly inserted 1 cell table. Then the two tages were removed.

This worked fine in ms word 2002 and ms word 2003. Of course there was a minor hickup, as you can't expect ms word macro's to be backward compatible to ms word 2000 when it comes to basic operations like find and cut.

The final problem arose from the variable length memo fields and sub reports. We had carefully put the autochange size (or whatever the correct name in english may be, we used the dutch version) property at Yes/True. That worked very well while viewing the reports in ms access. It created chaos when exporting the reports to ms access. Some of them expanded, some of them didnt. After a few days we arrived at a solution: all the memo fields went into subreports, even when there was no reason for them, and nothing was left in the details section of the main report. This finally solved the problem, though a little teaser remained: the tags introduced in the previous paragraph.

It turned out that the tags, when on the main form, did move down as required with the subreprots in some versions of ms office, but not in others. I couldnt reference the tags from vb-script when they were in the subreport. I still havent solved this problem, though my fellow worker probably did this in the past weeks.

Friday, November 10, 2006

Performance

Performance is a big issues in ms access.

First, it works with an interpreted language, vb. Interpreted languages are always slower than compiled languages, as interpreters generally translate each line of code as they encounter it.

Second, MS access generates a lot of network traffic. I don't know why, but it does.

Microsoft publishes a nice page with performance tips. Some interesting knowledge base articles:

  • http://support.microsoft.com/kb/209126
  • http://support.microsoft.com/kb/128808
  • http://www.microsoft.com/technet/archive/office/office97/maintain/off411ef.mspx?mfr=true
  • http://support.microsoft.com/kb/889588


The latter is particularly interesting, it contains several tips (or tricks, depending on ones point of view)

Someone asked me to have a look at an application a fellow worker had developed and which didnt perform on the network of our customer.

A first analysis learnt that the data involved was not much: most tables had very little rows, 10-50 rows, while a few had about 400 rows and one had 700 rows. The whole ms access data file was less than 4 Mb.

Yes, the database had been split in a program mde and a database file. Good practice in many environments, as it allows developers to work on the programs while the users can continue working with it.

The application works in a network environment, where the customers are in The Hague while the servers are in Amsterdam. The customers worked within a powerfuse and citrix network environment.


The performance problem appeared throughout the application, but was most noticeble in the opening of two forms. One took 30 seconds to open, the other 60. In stand alone mode, the forms openend within a second.

The network posed no problem, a database operator openened the forms on the server while located in Amsetrdam and found the same results.

Using this kb article, I asked him to rename both the database .mdb file and the program .mde file to a 8.3 format name. The result was astonishing: times went down from 30 and 60 to 10 and 20 seconds respectively. Astonishing. I had hoped them to half, a factor of 3 was above my expectations.

In a test environment, the option "Turn off the sharing violation notification delay" yielded no benifit. The same results appeared when I tested "Disable automatic short file name generation".

What did result in a substantial improved perfoamnce was the option to turn of local settings fo windows. This halved the time required for opening one of the windows, but did nothing for the other window.


Another thing was the option