October 2007 - Posts

Holding a Program in Ones Head

A posting very well worth reading.  Holding a Program in Ones Head

Posted by Tony | with no comments

Making copies of your database during the working day

The following question came up as part of a newsgroup thread.

When you say "make a copy every hour or two", do you really mean that your  normal practice during development is to retain multiple separate copies saved at 2-hourly intervals rather than simply overwriting a single backup copy every 2 hours?

Yes, because I'm a paranoid pessimist.  And I'm proud of that label.  You never know when something really weird might happen and you want a copy of an object from a few hours ago.  Or you change your mind and decide you want to go back to an older copy of an object or two.

Within Windows Explorer it's really easy to click on the MDB, Ctl+C, wait a moment for the hourglass to disappear, then Ctl+V.  Windows Explorer makes a copy of the file titled Copy of <insert your MDB name here>.mdb.   Then Copy (2), Copy (3), etc, etc.   Real easy.

At the end of the day or when I accumulate 5 or 10 I zip them up using Winzip's right click context menu into a zip file titled <insert your folder name here> zip.   I then rename the zip file to <insert your folder name here> yyyy mm dd.zip  i then move that zip to an archive folder, which I include on my backups.  In a month or two I those zip files.

Posted by Tony | 1 comment(s)
Filed under: , ,

Debugging intermittently failing VBA code

I had a problem where an API call would work when stepping through the VBA code but would intermittently fail crashing Access or give an "out of memory" error.  (Out of memory is Access's default error message when it doesn't know what else is the problem.)

Someone just posted a similar problem in the comp.databases.ms-access newsgroup.

From time to time I strike a problem where Access will suddenly shut down while running some code (Dr Watson message), wiping out any forensics (diagnostic traces such as debug.prints, etc).

Instead of using debug.print use a call to the following procedure.  Change the file name to suit your environment of course.

Sub LogToTextFile(Comment As String)

    Open "Q:\1 access\Fleet Mgmt\zzz Service log.txt" For Append As #1    ' Open file for output.
    Write #1, Comment
    Close #1

End Sub

Note that you have to close the file after writing each line.  The file doesn't get closed properly if Access crashes and you won't be able to see anything in the text file.

Tony

Posted by Tony | with no comments
Filed under: , ,

Optimizing Microsoft Office Access Applications Linked to SQL Server

Tom van Stiphout, fellow Access newsgroup denizen, alerted me to the following MSDN article: Optimizing Microsoft Office Access Applications Linked to SQL Server.  A link was also added to the Access Performance FAQ.

Note the following paragraph:

"Developers often migrate data to SQL Server expecting an improvement in application performance. Although performance does often improve, there are many cases where it remains the same or even degrades. In some cases, performance of certain queries degrades to an unacceptable level."

Posted by Tony | with no comments
Filed under: ,

Access / DotNet hybrid: yes it's possible

Tom van Stiphout starting a very interesting posting on Access and .Net interoperability.  Access / DotNet hybrid: yes it's possible Options

I mention this more as an intellectual curiosity as I think Access does a fine job.  And can easily work at the enterprise level once you use SQL Server, or equivalent, for the data storage.  Other tools can take two to five times as long to develop the same app.

Posted by Tony | with no comments
Filed under: ,

MAC address filtering is useless

SMAC is a powerful, yet easy to use MAC Address Changer (Spoofer) for Windows VISTA, 2003, XP, and 2000 systems, regardless of whether the network card manufacturers allow this option or not.

A link from Myth vs. reality: Wireless SSIDs which is very worth while reading.

Posted by Tony | with no comments
Filed under:

Self Documenting Code

I completely agree with the Self Documenting Code posting.

Below is some sample code for summing up all the costs of a service order with a small number of comment lines.  That's about right I'd say.

Now some may quibble with some things in that code.  For example I could've created a subroutine and called it for each of the child tables for which I was getting a total.  Sure, I could've but it's not that many more lines of code the way it is.  

Another question might be why am I storing such a grand total in the first place?  That's a violation of normalization.  Correct, however to get that number on various reports would require a great deal of extra load on the system.  I do have to ensure though that, among other things, whenever a child record is deleted that this routine gets called.  Which I forgot to do and a client pointed out.

And what's that comment line "@@@ check srTotalCost"?   The @@@ mean that's a comment I put in the code indicating I need to come back in an hour or two or three, once I've done other things, and double check or update the logic.  In other words a reminder I can quickly go Ctrl+F to find.

Public Sub CalculateServiceTotal(ServiceID As Long, blnUpdateTotal As Boolean, blnUpdateForm As Boolean)

Dim ServiceAmount As Currency, RS As DAO.Recordset, strSql As String
Dim ExternalInvoicesAmount As Currency, FiltersAndFluidsAmount As Currency
Dim ServiceTechCosts As Currency

    On Error GoTo CalculateServiceTotal_Error
    ServiceAmount = 0
    ExternalInvoicesAmount = 0
    ServiceTechCosts = 0

    ' ==== Sum up invoices belonging to this service
    strSql = "SELECT Sum(sriInvoiceAmount) AS SumInvoiceAmount " & _
        "FROM ServiceRecordInvoices  " & _
        "WHERE sriServiceRecordID=" & ServiceID & ";"
    Set RS = CurrentDb.OpenRecordset(strSql)
    If RS.EOF = False Then
        RS.MoveFirst
        ExternalInvoicesAmount = Nz(RS!SumInvoiceAmount, 0)
    End If
    RS.Close
    Set RS = Nothing
    If blnUpdateForm Then _
        Forms![Service Detail]!TotalInvoicesCost = ExternalInvoicesAmount
    ' === Sum up filters and fluids belonging to this service
    strSql = "SELECT Sum(srsServiceExtendedAmount) AS SumOfServiceExtendedAmount " & _
        "FROM ServiceRecordServices " & _
        "WHERE srsServiceRecordID=" & ServiceID & ""
    Set RS = CurrentDb.OpenRecordset(strSql)
    If RS.EOF = False Then
        RS.MoveFirst
        FiltersAndFluidsAmount = Nz(RS!SumOfServiceExtendedAmount, 0)
    End If
    RS.Close
    Set RS = Nothing
    If blnUpdateForm Then _
        Forms![Service Detail]!TotalFiltersAndFluidPrice = FiltersAndFluidsAmount

    ' === Sum up ServiceTechHours belonging to this service
    strSql = "SELECT Sum([srtHours]*[srtRate]) AS SumOfTechCosts FROM ServiceRecordTechs " & _
        "GROUP BY srtServiceID HAVING srtServiceID=" & ServiceID & ";"
    Set RS = CurrentDb.OpenRecordset(strSql)
    If RS.EOF = False Then
        RS.MoveFirst
        ServiceTechCosts = Nz(RS!SumOfTechCosts, 0)
    End If
    RS.Close
    Set RS = Nothing
    If blnUpdateForm Then _
        Forms![Service Detail]!SumTechCosts = ServiceTechCosts

    ' Total Service Costs
    ServiceAmount = ExternalInvoicesAmount + FiltersAndFluidsAmount + ServiceTechCosts

    ' @@@ check srTotalCost

   ' Update total cost
   If blnUpdateTotal Then
             If ServiceAmount <> 0 Then
            strSql = "UPDATE ServiceRecords SET ServiceRecords.srTotalCost = " & ServiceAmount & " " & _
                "WHERE srID=" & ServiceID
        Else
            strSql = "UPDATE ServiceRecords SET ServiceRecords.srTotalCost = Null " & _
                "WHERE srID=" & ServiceID
        End If
        CurrentDb.Execute strSql, dbFailOnError
    End If

   On Error GoTo 0
   Exit Sub

CalculateServiceTotal_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CalculateServiceTotal of Module mdlService"
    Exit Sub
    Resume
End Sub

Posted by Tony | with no comments
Filed under: ,

Have you made a recent copy of your files and photos?

And is that copy offsite?  Have you made that copy in the last week or so? 

And not on a thumb drive either!   You have to have at least four or five copies because thumb drives and DVD-Rs can also die or be in a fire.

Daughter of Ted Byfield burned in his home

Despite the physical loss, Mr. Byfield said he was grateful firefighters were able to salvage one of his computers that had manuscripts for a set of Christian history volumes he is putting out next year with a group of people.

"I look inside the ground floor window and there's my computer with two or three years work on it. ... Somehow they saved it, I don't know how. But it could've been a real disaster."

My sister and brother-in-law just lost their laptop hard drive.  It had been running really slow at times this last month (They thought they had a virus.)  It finally failed with a BSOD (Blue Screen Of Death.)   And now I can't retrieve anything from that hard drive.   I can see there's a hard drive there but no files.

So they've lost about four years photo's of their winters spent in the Maldives and trips to India, Nepal, Sri Lanka,  and their kids growing up.  This includes camping in the U.S.A visiting all the standard tourist places such as the Grand Canyon and Carlsbad Caverns.

<sigh>

Posted by Tony | 1 comment(s)
Filed under: