22 May 2014

ESum for use in MS Access databases

Allen Browne has the excellent ELookup and ECount functions, but for some reason no ESum function.

Here is my version, based on Allen's code:

Public Function ESum(Expr As String, Domain As String, Optional Criteria As Variant) As Variant
Dim db As DAO.Database          'This database.
Dim rs As DAO.Recordset         'To retrieve the value to find.
Dim strDomain As String         'Table to look in
Dim varResult As Variant        'Return value for function.
Dim strSql As String            'SQL statement.

'Purpose:   Faster and more flexible replacement for DSum()
'Arguments: Same as DSum.
'Return:    Value of the Expr if found, else Null.
'Author:    Harry Driscoll, based on Allen Browne's ELookup. allen@allenbrowne.com
'Created:   May 2014
'Note:      Requires a reference to the DAO library.

On Error GoTo errhandler
    
    strDomain = Replace(Domain, "[", "")
    strDomain = Replace(strDomain, "]", "")
    strDomain = "[" & strDomain & "]"

    'Initialize to null.
    varResult = Null

    'Build the SQL string.
    strSql = "SELECT Sum(" & Expr & ") FROM " & strDomain
    If Not IsMissing(Criteria) Then
        strSql = strSql & " WHERE " & Criteria
    End If
    strSql = strSql & ";"

    'Lookup the value.
    Set db = DBEngine(0)(0)
    Set rs = db.OpenRecordset(strSql, dbOpenForwardOnly)
    If rs.RecordCount > 0 Then varResult = rs(0)
    rs.Close

    'Assign the return value.
    ESum = varResult

Exit_DSum:
    Set rs = Nothing
    Set db = Nothing
    Exit Function

errhandler:
    MsgBox Err.Description, vbExclamation, "ESum Error " & Err.Number
    Resume Exit_DSum
End Function

29 July 2011

How to Take Good Photos with an Entry Level DSLR

My pointers on taking good photos with an entry level DSLR, in order of priority.
  1. Take lots of photos!
    Practice, practice, practice! Don't be shy about taking 10 photos of the same scene or 10 photos of a person. Have a look on the LCD and even if you think the first photo was pretty good, take 9 more just to be sure. Sometimes it can be hard to tell if the first photo was in perfect focus with no blur.
    Gone are the days of trying to spare the film to save cost and hassle, memory sticks are cheap so take advantage!
  2. Set the White Balance
    Leaving the camera in Auto mode may default the White Balance setting to Auto, which will usually be fine. Checking the White Balance setting, especially when shooting indoors under incandescent lights makes the colour of photos look much more natural than the auto setting. Beware, leaving the WB setting as Incandescent when shooting outdoors will make your photos look very blue!
  3. Avoid the built in flash
    Indoor photos shot with the built in flash never really look quite right. Especially indoors, the photos always end up looking like they were shot with a disposable camera. Instead, try opening curtains and blinds, or get your subject to stand near a window. Or set the ISO sensitivity as high as it will go instead of using the on board flash. If you do have to use a flash, use a diffuser ($2.99 on eBay).
  4. Use the built in flash!
    When outdoors, and especially when the sun is directly overhead, use the on board flash to fill in any shadows. When taking photos of people, if the sun is behind them use the flash to lighten up their faces. Use it judiciously, try and only use the on board flash when there are significant shadows on peoples faces. And use a diffuser.
  5. Switch to 'A' mode - or at least use the scene functions
    Aperture priority opens up the world outside Auto mode and allows you to set the White Balance, the power of the on board flash, and allows you to set the Aperture.
    Set the aperture to a small number (as small as it will go) when taking portraits because this should nicely blur the background of your photos (bokeh). Wide aperture (small number) will also help with indoor photos because more light is getting in the lens. Entry level lenses often won't go to a really small number (like 1.4) but get set the number as small as it will go for portraits.
    Landscape shots should be taken with larger apertures, and your entry level DSLR will usually have a 'landscape' mode which will set this automatically.
  6. Set the Auto Focus to centre point only
    This really is a control thing. Using just the centre point lets you decide exactly what is in focus. If you want to focus on something which will end up at the side of your shot, point at it, half depress the shutter release, reframe, and shoot.
Other things to do:
  1. Set the clock!
  2. Set the flash to 'off' instead of 'auto' and only pop it up when you need it.
  3. Switch the camera to burst mode, which is not the default. If you press the shutter release button once you'll only get one photo, burst mode will kick in if you hold the shutter release button down. (Burst mode will keep clicking until you let the button go.)
  4. Get a UV filter for your lens. This is really just to protect the lens from scratches (although there are some who would suggest this is not necessary).
  5. Get a Polarising filter for your lens. This is especially useful for landscape shots with lots of blue sky or where there is a lot of reflection from water to cut out.
I'm sure I'll think of more.

Update: I did think of more!

  1. Zoom in closer than you think you should for photos of people, either portraits of individuals or photos of groups of people. It really adds impact to the photos and gives them a professional look.
  2. Process your photos using Google Picasa to fix any red eye, adjust colours, or snip out unwanted parts of a photo. Picasa is also a really easy way to upload photos to the web, and an easy way to email small, low res photos to your friends and family without sending them massive attachments.

28 June 2010

How to make computers faster!

Want to make your XP computer with Office 2003 run faster?
How to turn off the speech recognition and the handwriting recognition features in Office 2003: http://support.microsoft.com/?kbid=823586
This has done wonders for my Outlook memory consumption. It dropped from about 150MB to about 30MB. Minimising Outlook when you aren't using it does good things as well.

17 June 2010

Progress Bar on an Access Form

To create a progress bar on a MS Access form is a pain if you try and use the built in Progress Bar control.

Instead, use this gem which I stumbled across on the Microsoft website.

The explanation and code there is a bit complicated and ugly, and didn't exactly do what I wanted anyway. So I created my own little Sub to create a progress bar, with some text overlaid.
Private Sub ProgressBar(strCaption As String, intStep As Integer, intWidth As Integer) lblProgressLabel.Caption = strCaption pbFill.Width = pbFrame.Width / intWidth * intStep Me.RepaintEnd Sub
To make it work you need three controls on your form: two rectangles and a text label.

In design mode, add in the first rectangle and make it the shape you want. Call it 'pbFrame'. All the defaults should be fine.

Add in the second rectangle and call it 'pbFill'. Set the BackColour to whatever colour you want the progress bar to display with. I usually use blue. All the other defaults should be fine.

This second rectangle needs to be overlaid on top of the first, so drag the 'pbFill' rectangle roughly over the top of 'pbFrame'. Now select both rectangles and choose "Format:: Align:: Left", then "Format:: Align:: Top". With both rectangles still selected choose "Format:: Size:: To Tallest". The width doesn't really matter because it is going to be reset later anyway.

Add in a text label and call it 'lblProgressLabel'. I set the Fore Colour to white, and make sure you set the Back Style to Transparent. This label needs to be overlaid on top of the two rectangles, so just repeat the steps you used for the second rectangle. This label also needs to be the same with as 'pbFrame' so select both 'pbFrame' and 'lblProgressLabel' and choose "Format:: Size:: To Widest".

In your Form_Load event, add in the following:

Private Sub Form_Load() pbFrame.Visible = False pbFill.Visible = False pbFill.Width = 0 lblProgressLabel.Visible = FalseEnd Sub
When you want to use your new Progress Bar, make it visible first with:
pbFrame.Visible = TruepbFill.Visible = TruelblProgressLabel.Visible = True
Then, call the Sub as follows:
ProgressBar "Half way through!", 5, 10
The text will be displayed on your progress bar, the 5 represents your progress and the 10 represents the total number of increments. The 5 could be a recordsets absolute position and the 10 could be your recordsets total recordcount.

Don't forget to hide it at the end with:

pbFrame.Visible = FalsepbFill.Visible = FalselblProgressLabel.Visible = False
Enjoy!

14 August 2009

Gem's of knowledge on the Microsoft Support website - Automatic Inactivity Shutdown for MS Access

Sometimes I get help in the most unlikely of places, such as the support.microsoft.com website!
I was looking for a way to kick a user out of an MS Access database after a period of inactivity (mostly so that changes could be made to the front-end).
A hidden form with a small amount of VB code, opened automatically when the database launches. Superb!

08 August 2009

MS Access (or SQL Server with an Access .adp) vs MySQL with php

I don't claim to be an expert programmer, I sometimes stumble through copying bits of code as needs be. My focus is on corporate workgroup projects rather than on whole corporation projects so that's not really an issue.

But, it is because of this that I find working with MS Access much more palatable than trying to work with MySQL.

Don't get me wrong, MySQL has it's place. Speed, scalability, multiple concurrent connections, all good virtues of a database system. And I am also well aware of the disadvantages of MS Access, such as speed, scalability, multiple concurrent connections, or rather lack thereof.

But for me, the advantages that MS Access presents are enough to overcome the shortfalls.

It is super fast and super easy to set up a complex table structure from scratch and get a graphical representation (with the Relationships Window) of that structure. Then, it is super fast and super easy to set up simple queries on that data. Drag and drop the fields you want. After that, forms can be created with relative ease, use the wizards or drag and drop fields you want displayed.

Before the MS bashers flame me in the comments below, remember the projects I am involved in are usually corporate workgroup projects so multiple concurrent connections aren't really important. It would be unusual for me to see as many as 10 people logged in at any one time. Not that they couldn't, it would just be unusual.

Speed doesn't seem to be too much of a problem either. Well, at least I don't get too many complaints about speed from users that couldn't be explained by other factors. A slow computer running IE6 (yes, the company I work for runs IE6!) connecting to a MySQL db hosted in another state will most likely be just as painful as the same computer connecting to a MS Access db via Citrix.

Yes, MySQL is free. But you can't say there is no cost. Learning php to develop web based forms isn't straight-forward. Learning that stuff is hard, learning Visual Basic really isn't. The development path for a project that is quite often replacing a horribly complex spreadsheet is much less of a challenge using MS Access and Visual Basic than it is using MySQL and php.

I'm not trying to change anyones mind with this post, MySQL and php developers may well be aghast at the blasphemy of suggesting that MS Access might be a more appropriate choice, I really just want to present an opinion based on my experiences. Developing an MS Access system for a workgroup project is easier than trying same exercise in MySQL.

What is this Blog

I hope to use this blog provide people with information they might find useful or interesting.

I have a lot of experience with MS Access, MS Excel and Visual Basic coding for those products so you will see a fair bit of information about those topics here. As an addition to that, I have been working on a number of projects which use PDA devices, or Windows Mobile phone devices to allow users to collect data in the field and remotely upload to a central server.

The posts here will be used to explain how I have implemented some tasks, especially where other online explanations have needed some further clarification or work to get the end result.

Comments are welcome.