vb123.com.au
by Garry Robinson
One of the most successful user interfaces that Microsoft have created for their products is the Wizard. A wizard is a way of breaking up what would be a complex interface into a series of simple pages. This article concentrates on how you can put together a number of Wizards inside your Access application. Included with the article is a number of Access objects that you can import into your application so that you can build your own Wizards.
After reading Peters Vogels recent articles about user interfaces , I began to ponder how I could make the shareware that I have developed a better experience for users. This includes one form that has over 75 different controls on it. So I decided that I would aim to make the whole system easier and give the users a head start by using a wizard to fill in some of the fields on the form. Then I decided to build more wizards for other activities that were explained in the manual but were unlikely to be used by my shareware audience. At this stage I had to generate a more general way of managing these internal wizards as I didn’t want multiple versions of the form that was driving the wizard pages. The end result is that the wizards now act as guides to my software, the software now looks more professional and users are reacting more positively to the software. Maybe the wizard interface can do the same for your software.
| NOTE: When building an Access wizard, I use the Access Workbench favorites to switch quickly between the MDA database and a database that tests the wizard. I also store the MDA file in the C:\Documents and Settings\Garry Robinson\Application Data\Microsoft\AddIns folder so that I can debug it and change it quickly. Finally I regularly use the quick backup option in the workbench to make copies during the daya becuase building a MDA wizard is difficult and error prone. |
There is probably no exact definition of what a Wizard UI is but if you look a the Microsoft Examples such as the New Form Wizard you will find the following characteristics
8) The fields on the forms will have intelligent default values.
To demonstrate how you would go about building your own wizards, I could think of no better example than a wizard which would help you build a wizard. I will call this Wizard WizWiz from now on. At this stage its time for a confession. WizWiz is a modified version of the Microsoft Wizard Building Wizard (see sidebar). The different approach that I took was to assume the design principle that the wizards that this system would produce an Internal Wizards rather than a wizard that you run as an Add-In. The other change that I introduced to WizWiz an extension to easily manage a number of wizards inside the same database. And while I was at it I stripped out some of the code that was used for managing Add-Ins.
So to start the process off, open the download database called WizWiz.MDB. Once you have tested the software, import the all the Tables, Forms and Modules with a prefix of "Z_" into your own database.
Open the form called z_Wizard. This can act as your control center for the different Wizards in your application. Now click on the Build Wizard Wizard button and this will display Figure 1

Figure 1 - Getting started with your own wizard
The first page of WizWiz asks you 3 important questions. The first is the identifying code. This is the key that ties all the forms of the wizard together. In figure 1 my identifying code is "Graph" which means that all the forms will be have a suffix of Graph. The "Name" is used for the heading of each page. "Description" will initially be used for all the pages in your wizard. You will change the indvidual descriptions in the system tables later. In figure 1, "Build A New Internal Wizard" is the name used in the wizard and "First You need to give the Wizard a code, a name and general description" is the description.
The next page of WizWiz is shown in Figure 2. Now you are going to give the wizard a prefix that follows your favorite naming conventions. You are also going to specify how many pages your wizard will consist of. Do not be concerned if you haven't made a final decision on the number of pages. As the wizard system is table driven you will be able to alter your selections later on.

Figure 2 - Establishing the names and number of pages that your wizard is going to use
In the example that I have shown, I have asked the wizard to generate 3 pages using a page prefix "My_Wizard". This means that WizWiz will generate forms called My_Wizard1_Graph, My_Wizard2_Graph and My_Wizard3_Graph.
Now click on the next button and you are presented with the final page as shown in figure 3. Here you fill in your company details, the version number (where 130 = version 1.3) and the year that your wizard was built.

Figure 3 - Completing The Build Your Own Wizard Wizard
When you click on the Finish button, WizWiz will then copy a form called z_WizPage_Template and make a new page for the full sequence of pages requested. WizWiz also adds a number of records to the system tables which are called z_wizPages and z_WizInfo.
If you wish to add your own logo and modify the layout of the template, you should do this before you start. WizWiz has been setup in such a way that you can modify the template page to suit your own wizard requirements and the next time you run WizWiz, your new pages will reflect your changes.
The wizard comprises of one key form called z_WizPage_Main and an accessory form called z_WizPage_help. The main form has the Wizard Help, Cancel, Back, Forward and Finish buttons on it and all the supporting software to drive the internal pages for your wizard. When you start up the wizard, you would use the following open form statement to startup the wizard that we just completed where Graph is identifying code
DoCmd.OpenForm "z_WizMain", _
acNormal, , , , , "Graph"
The Form_Open event starts calls the internal pages of the wizard through a unbound subform control as follows
wzCurrent = Me.OpenArgs
wzPrefix = vGetuzInfo(0, 1)
wzName = vGetuzInfo(1, 1)
This vGetuzInfo subroutine will retrieve a record set from the z_WizInfo table using a query as follows
SELECT * FROM z_WizInfo WHERE wizcode = '" & wzCurrent & "' and Key = " & intKey
So from our previous example, we would open up the first wizard page called My_Wizard1_Graph using code in the Form_Load Event.
Me!frmPage.SourceObject = wzPrefix &_
intWhatPage & "_" & wzCurrent
All the buttons are made active or not using a subroutine called SetupNavButtons. This function works using recordsets based on the following query
SELECT * FROM z_WizPages WHERE wizcode = '" & wzCurrent & "' and PID = " & intWhatPage
So the buttons are turned on and off according to the following table of possibilities.
All the buttons are made active or not using a subroutine called SetupNavButtons. This function works using recordsets based on the following query
SELECT * FROM z_WizPages WHERE wizcode = '" & wzCurrent & "' and PID = " & intWhatPage
So the buttons are turned on and off according to the following table of possibilities.
|
Button |
1 |
2 |
3 |
4 |
5 |
|
Cancel |
On |
On |
On |
On |
On |
|
Back |
On |
Off |
On |
Off |
On |
|
Forward |
Off |
On |
On |
Off |
Off |
|
Finish |
Off |
Off |
Off |
On |
On |
Table 4 - The button combinations that you can set for your wizard.
So open up the system table called z_WizPages and look at the buttons column for rows with a WizCode of "Make". As WizWiz is a 3 page wizard, e have a Next button on the first page, Next and Back on page 2 and Back and Finish on page 3. WizWiz will setup your new wizard using the same button sequence. Whilst you are looking at this table, the column Heading is what appears at the very top of each page whilst the column Text is the description that appears on each page.
Now the wizard will display your first page and display the buttons. How does the software run code under each button for a series of unbound forms ? Well the answer is through form methods and in each of the pages you will find a series of functions called GoNext, GoBack and Go Finish. One of these is shown
Function goNext()
goNext = True
end function
This public Function is called from the form z_WizMain and then the new page has its buttons turned on and off as appropriate.
Set frmCurrentPage = Me!frmPage.Form
If frmCurrentPage.goNext() Then
intWhatPage = intWhatPage + 1
Me!frmPage.SourceObject = wzPrefix & _
Format$(intWhatPage) & "_" & wzCurrent
Call SetupNavButtons
End If
I also added a method called showHeadings which will allow you to pass the heading and description of the page to be displayed on the unbound form.
All of the above was background material and was mainly designed to give pointers to the inner workings of your new wizard. What you really need to know at this stage is how you would add you own controls and code to start making your wizard work. If you look at Figure 1 again you will see that there are 3 fields that need to be filled in by the user. You may at this stage open the form z_WizPages1_Make in design mode and look for the function GoNext. As we are heading off to the next page, we need to store the entries to the fields on the screen. For programming simplicity, I have used a public array variable call wzVariables. This as with other shared public variables are stored in the Module "z_Wiz". So the user entries are stored as thus
wzVariables(1) = Me!txtCode
wzVariables(2) = Me!txtName
wzVariables(3) = Me!txtDescribe
And if the user returns to the current form using the Back button you need to check if the variables have been used and show them on the screen using code as follow.
If Not IsNull(wzVariables(1)) Then
Me!txtCode = wzVariables(1)
End If
You also need to write a little bit of the same code on the goback function of each form to save any current entries. As these are global variables, it is a good idea if you clear them when starting up the wizard. A function called ClearWzVariables will do this for you.
To complete the whole process you need to write the actual software that the wizard is going to perform under the Finish function on the last page in the wizard sequence. Have a look at the form called z_WizPages3_Make where you will see all the code that builds your wizard pages. I have included some snippets below
Set rstWizPages = CurrentDb.OpenRecordset _
("z_WizPages", dbOpenTable, dbAppendOnly)
' Now we need to loop through the total number of pages required and
' make the new templates
For i = 1 To wzVariables(5)
newPage = wzVariables(4) & i & "_" & wzVariables(1)
DoCmd.CopyObject , newPage, A_FORM, templateName
With rstWizPages
.AddNew
!PID = i
!wizCode = wzVariables(1)
!heading = wzVariables(2)
!Text = wzVariables(3)
If i = 1 Then
' Setup the forward button
!Buttons = 2
ElseIf i < wzVariables(5) Then
' Setup the back and forward buttons
!Buttons = 3
Else
' Setup the back and finish buttons
!Buttons = 5
End If
.Update
End With
Next i
rstWizPages.Close
If you are going to put the Finish button on more than one page, you will have to make this a public routine.
Wizards are a very legitimate user interface that can be used in your applications for complex tasks or for setting up complex forms. As Access programmers, you are probably far more aware of them than your users who really only want to learn the minimum to get there job done. Bearing that in mind, you can certainly enhance your software by using WizWiz to make professional looking wizards. As a rule they take a bit longer to program as you have to coordinate a number of forms together to make an interface. But if they replace user manuals for the same tasks, it could be easily argued that they will be cost effective to produce. So make sure that they are appropriate for the task at hand and abracadabra.
The sample database is included in the zip file
If you do NOT own "The Toolbox", Click
here to find out how to purchase The Toolbox.
Author Bio.
Garry Robinson is the founder of GR-FX Pty Limited, a company based in Sydney, Australia. If you want to keep up to date with the his latest postings on Access Issues, visit his companies web site at http://www.gr-fx.com/ or
FX Wizards - A series of Access
wizards to help your productivity.
Microsoft FreeStuff
Consolidation Queries
Making Microsoft Graph Work Better Better In Access using Visual Basic
Samples of Menu and Toolbar
Protection
Click on the following button
to jump to the next page in the document loop.
Get Good Help Here
If you need help with a database or
Office programming,
our Professionals could be the answer because we have worked on many
similar solutions
Frontpage Conversions
We have converted vb123.com to Expression Web,
contact us if we can help you move to the latest Microsoft web tool.
About The Editor ~ Contact Us
Garry Robinson writes for a number
of popular computer magazines, is now a book author and has worked on
100+ Access databases. He is based in Sydney, Australia