July 2007 - Posts

Other Access blogs

Bored?  See Jeff Conrad's list of such.

Posted by Tony | with no comments
Filed under:

Closing/Deleting Items in Collections

This always gets me for a minute or two.  I am just creating some code in behind a form which will close all the other forms.  The idea being that another hidden form is used to determine if the user has not done anything in a half hour.  if so they get booted out.    However i want to display a message indicating they got kicked out on a form.   But I want to close all the other forms so there are no tables open in the backend MDB.  Thus others can do backups, compacts or work on the tables or indexes.

Initially I had the following code

For Each frm In Forms
    DoCmd.Close acForm, frm.Name
Next frm

But that was closing some forms and leaving others open.  Say what?   Oh yeah, I reminds myself.  When you go through the open forms collection closing forms the number of objects is reduced by one as you close each form.   This logic actually closed every second form.

Thus you need to start at the end of the collection and go backwards.

For i = Forms.Count - 1 To 0 Step -1
    If Forms.Item(i).Name <> "zMsgBoxThenExit" Then _
        DoCmd.Close acForm, Forms.Item(i).Name
Next i

Note that this also applies if you are deleting objects in a MDB, fields on a table and so forth.  Anything that is a collection.   You have to do the -1 to 0 logic because collections and such in VBA start at 0 not 1.

Posted by Tony | with no comments
Filed under: ,

Date entry short cuts

Did you know that you can enter just the day and month, with spaces between the two, and Access will add the year and insert the slashes.  (Or whatever your separator character between the dates is?)    Of course you really want to be careful on this tip when you are in the first day of the new year entering transactions from the last working day of the previous year.

Or you can enter just the year, with all four digits, and the month and Access will add the 01 for the first day of the month?

Note that I never use input masks and my machine has the date format in the regional settings set to yyyy-mm-dd.  So I can always see the century as well.  Just in case.  

A client likes displaying his dates in dd-mmm-yy format, ie 31-Jan-07.   I prefer to always display the full century as in one situation 12 records in a table with 100,000 records had the wrong century.   Just due to fat fingers.

Posted by Tony | with no comments
Filed under: ,

You never want to base any kind of form directly against a table

I was asked the following question:

You made a comment in 'Worse Than Failure' The Sharon System and i was wondering if you could elaborate on it. You said

"Access works very well with controls and forms bound to queries/views/whatever against SQL Serer, etc. Of course you'd never want to base any kind of form directly against a table. "

I work a lot in Access Front End against SQL Server using unbound forms and I was curious why you would never want to base any forms directly against a table.

You'd never want to work directly against a table whether it resides in Access, SQL Server or elsewhere.

There are basically about three types of tables.   (Of course I'm generalizing.)  Master aka lookup tables holding data such as transaction types, provinces or states, activity codes, departments, locations, etc, etc with typically dozens or a few hundred records.   Then there are tables holding data such as customers, units, employees and such with hundreds, thousands or tens of thousands of records.  Finally transaction tables with tens or hundreds of thousands or more records.

You would always want to sort lookup by something such as alphabetically or by province/state or frequently by a sequence number.  So these would need a query to at least sort by this value.   A sequence number would put the more commonly used items at the top of the list or combo box.  For example in a list of payroll transaction types RT - Regular Time, OT - Over Time and DT - Double Time would come first and then other values.  However typically you'd use a continuous form and display all the records.  I also would sort inactive records to the bottom.

A customer, employee or equipment table with a few thousand records you might or might not use a continuous form with some sort of lookup fields at the top to allow you to quickly shorten the number of records.  Or you may display the form with no records in the initial view but as soon as the user puts in a lookup value you'd display a limited set of records.   The Like operator in a query becomes very useful.

What is especially interesting is how quickly a few characters of the beginning of the first and last name narrows down the records.  In a sample database of 10,000 names even just J for the first name and S for the last name gets the number of records down to a few dozen.  Jo and Sm narrows it down to three or four records.

Finally the transaction tables.   Here you really would want to start limiting your data by a date range.  For example to the start of the last pay period if hourly transactions.  Then allow for more filters on employee name, job number or other.

Posted by Tony | with no comments
Filed under:

Calling a subroutine on another form

I never knew that you could do this.   I was asked to give some assistance at a friends place of work and was rather startled to come across the following line of code.

'Update the calculated hours shown on the TransactionTotals Form
Call Forms.TransactionTotals.UpdateEmployeeHours

Nice.  I can see how that would be useful at times.   I just setup a routine myself for enabling/disabling command buttons on a main menu from a global options form.  

The called routine needs to be a public routine.  And the forms name can't have any blanks in it.  Or maybe it can but enclosing the form name in square brackets didn't work so i don't know the syntax.

When I have some more time, and I have his permission, I'll document some of the interesting UI we put in that system to make the data entry as clear and rapid as possible.  For example the above TransactionTotals form knows what kind of hours the employee usually works so flags any entries with hours below the standard value in yellow and any entries with hours over the standard values in red.  Of course if the employee has the correct number of hours then it's green.

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

Windows Vista, ODBC and SQL Server 2005

The following has also been added to the Access Performance FAQ page.

For the best connection string for a DSN-less connection to SQL Server 2005, switch providers to the SQL Native Client with the following:
"ODBC;Driver={SQL Native Client};Server=<servername>;DATABASE=mydatabase;Trusted_Connection=Yes"
by Rick Byham of Microsoft.  See the thread Vista, ODBC and SQL Server 2005

Posted by Tony | with no comments

Access 2007 design view performance on Windows Vista vs Windows XP

A very interesting thread brought out some interesting differences in the networking stack in Windows Vista.   The following paragraph was added to the Access Performance FAQ page.

"If I disable autotuning on the TCP stack in Windows Vista I no longer suffer from this problem. ... until I upgrade to Windows server 2008 I won't be enabling autotuning on my Vista client."  See the thread Access 2007 Design view performance on Vista vs XP initiated and finished by cpf_profiles   See Receive Window Auto-Tuning on Vista for more technical information including KB articles.

Posted by Tony | with no comments

goto

goto (I love the cartoon's disclaimer.)

That said I do use goto's in one major situation.  At the beginning of any routine to check conditions and immediately exit.  For example if I want to update some rates has the service tech rate been entered on the form.   I see no reason to have lengthy If then else endif statements with indented code for no particularly good reason.

Other times, which don't happen often, well, you have to.  There is no easy way to code around it. 

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

Clippy

Amusing anecdote about our forgotten and not missed friend Clippy - She typed in 'God damn clippy' by Michael Kaplan

Posted by Tony | with no comments
Filed under:

Currently reading the Harry Potter book

Pretty grim reading in places for a 12 year old.

Posted by Tony | 2 comment(s)

Using Terminal Server when a disaster strikes nearby

David Fenton, respected denizen of the comp.databases.ms-access and recently the microsoft.public.access newsgroups, has an interesting posting on a client who has an office near the recent New York steam pipe explosion.

OT: Disaster Recovery

I've read of similar situations in the past where there's a nearby incident of some sort, such as a large fire, or chemical leak.  The power was still on but the employees couldn't use the systems.    This also illustrates why employees should keep their files on the server and so on and so forth.

Posted by Tony | with no comments
Filed under:

The Sharon System

The Sharon System from the Worse Than Failure web site is a very interesting story on a person who clearly has not a clue about database design principles.  Or how to do things a basic proper way.  Or even Access.

I came across one such person many years ago who was doing some contract work because she was a friend of the administrator from the same church.  My contact told me that the person said there was no way the report could be sorted by legal land description instead of by last name.   Sure, you'd have to break up the legal land description into the components and sort from the right hand component and go left but no big deal.

It is also clear that the person writing the article didn't know a lot about Access either.   Smallint is a term used by SQL Server and other folks and is not a term used by Access folks.  We would use the term integer instead. 

Some of the comments are clearly written by folks who don't have a clue about Access.  Indeed I'd even use the term bigot.   I posted my comments.  <smile>   I'm sure I'll get some flack.

Posted by Tony | with no comments
Filed under:

One feature that DAO is missing - resetting autonumber seed

Using queries you can insert and delete a dummy record thus resetting the autonumber seed higher.  I don't know why you'd want to do this of course as the user should never see an autonumber value. 

In ADOX you can reset the autonumber seed value to be anything you want.  In Jet 4.0, used by Access 2000, 2002/XP and 2003 this can get occasionally screwed up, especially if you're not up to date in the service packs.   You can't get to this value in DAO.  But ADOX does allow you to change this value.

Allen Browne has some scenarios and sample code at his page Fixing AutoNumbers when Access assigns negatives or duplicates

Posted by Tony | with no comments
Filed under: ,

When is an autonumber value allocated?

An autonumber value is allocated as soon as a user hits one character or digit in any field in a new record.  If, a millisecond, later another user or program creates another record, even if no data has yet been saved by the first user or program, the next autonumber value will be used.

  Create an MDB with one table with an autonumber field and another field such as a text field.  Open that MDB from two instances of Access.  

Autonumber field screen shot

In one instance of Access put any character in that field and do not tab or enter in the field.  You will see the autonumber set to 1.  Notice the triangle in the record selector area on the left hand side of the screen.  It will change to a pencil indicating that "You are editing this record; changes to the record aren't yet saved." (from Access 97 help.)

In the other instance of Access against the same MDB also enter a character in the text field.  You will note that the autonumber is now 2.   And also that the triangle in the record selector has changed to a pencil.

The appearance of the 1 and 2 of course assume that the NewValues property of the autonumber field is set to Increment and not Random.

This is not true when using SQL Server to store your data.  SQL Server only assigns an autonumber value when the record is saved.   I have no idea about other data storage mechanisms such as Oracle, DB2 or MySQL.

Posted by Tony | with no comments
Filed under: ,

Steve Schapel's thoughts on Customized vs Commercial software and Desktop vs Web

Steve has some useful postings on the above topics.

Customised vs Commercial   One solution if you are looking for accounting systems is to choose a Microsoft Access based accounting system for which you can purchase the source code.  Thus you can customize the system to suit your requirements.

Desktop and Web applications 

Posted by Tony | with no comments
Filed under:

What does DAO have that ADO/ADOx/JRO do not?

An interesting and still very relevant seven year old article by Michael Kaplan aka michka. 
What does DAO have that ADO/ADOx/JRO do not?

Posted by Tony | with no comments
Filed under: ,

Egyptian poet pleads for stolen works to be returned

Egyptian poet pleads for stolen works to be returned    The relevant paragraph is

 "Mersal's office was broken into in the early hours of June 17 and her electronics and black laptop bag were stolen. Inside the bag were both backup copies of her work -- an electronic memory stick and a black notebook filled with Arabic writing scribbled in pencil."

 Presumably your corporate backup is in decent shape.  How is your personal backup?   Is the backup media, likely CDR or DVDR in a different location than your computer?   Are you backing up files other than just what appears in the My Documents folder?  For example if you use Outlook or Outlook Express those files are somewhere else.  What about other software applications settings that are important?   What about family photos?  Have you tried restoring a few files from your backup occasionally?

 I use my own folder for my files including my email and newsgroup postings.  I've been using this for at least fifteen years which long predates Windows 95.  Every time I install a new hard drive I have to spend five or ten minutes changing all the defaults in various software products such as Word, Excel and others    As my email and newsgroup software use INI files to hold their setttings they do not require any registry settings to be transferred.

 Several times a week I create an encrypted zipped file of this folder.  Zipped it's about 1.1 Gb.  This then is copied to my tower computer if I'm at home.  I then burn my last three backups onto a single DVDR and put in a fire resistant fileing cabinet.  Frequently I will put that backup in my safety deposit box.

 Note that a fire proof safe or filing cabinet isn't actually fire proof.  It is fire resistant and has a one or two hour rating.  Sure, almost all the time fire fighters will get the fire out in that time.   Also note that the one or two hour applies to paper.  Not plastic.  So get those backups offsite!

Posted by Tony | with no comments
Filed under:

Amusing Developer Stereotypes

Such as Copy/Paste Guy, Google Gal and more.  Beyond Elvis, Einstein and Mort: New Programming Stereotypes for Web 2.0

Posted by Tony | with no comments
Filed under:

Excel as a database

Excel as a database The cartoons are hilarious.  Some of the comments are pretty good. 

Posted by Tony | with no comments
Filed under:
More Posts Next page »