Friday, 27 November 2009

MS Access Running Queries

MS Access is the worst piece of software I have ever had the misfortune of using. It is so ubiquitous that M$ see no need in improving its appalling user interface. People use it because people have always used it, and the money just keeps flowing in.

Thursday morning saw me wrestling with an Access report to fix a formatting bug. It is the hardest thing in the world to get any help from the internet on Access because it is used by so many newby and first grade programmers who know NOTHING about programming that the useful information (if indeed there is any) is buried under a huge pile of misinformation bad advice, wrong advice and general bullshit.

After a couple of hours of trial and error here is how I found to run a query and process the resulting data.

' This runs the query I wanted to run. The key is knowing to use CurrentDb.
Set rst = CurrentDb.OpenRecordset("qryLicenceProductKeys_GetOrderID")

' You can access the fields with
rst!FieldName eg rst!OrderID etc

I hope this snippet may be of some use to those of you out there who cannot for the life of them work out from the internet detritus how to perform, what obstensibly should be a simple task.