Introduction - Access2003.
Since we have tried many options with Office Assistant earlier, we will do some fun stuff this time. Those who entered straight into this page may like to look into the following Topics. The links to the earlier Articles are given below:
- Message Box with Office Assistant
- Message Box with Menu Options using the Office Assistant
- Message Box with Check Box type Menu with the use of Office Assistant
- Command Button Animation (Visit this page to Link the Microsoft Office Library File to your Project).
We all know that we can select the Office Assistant of our choice from the Help Menu of MS-Access or other MS-Office Applications as well. Instead, we will design a Form in MS-Access to organize all the Office Assistant Characters available on our PC on the Form, display them and select the one that we like, and set it as the default Office Assistant, as we please.
A sample image of the Program Run is given below:
We need a small Table with the Office Assistant's File names in a List Box as shown on the left side of the Form above.
Designing a Table and Form.
- Create a Table with the Field Names as shown below, save it with the name Assistant and enter the Data from the List.
Out of eleven items, the first seven files are in the same location and others are found elsewhere. Before entering the above list into your Table it is a better idea if you run a search for all the files with the File Extension.ACS on your machine and use those files in the list.
To search for the files, select Start -> Search -> For Files or Folders -> All Files and Folders and enter the search term *.ACS on the Search Control and Click Search. When the search is completed, note down the correct path of all the files displayed and then enter them into your Table with the full Path Name.
- Design a small Form and set the Properties of the Form and controls as given below to match the design.
- Create a List Box on the Detail Section of the Form. Click on the List Box (if it is not selected), Display the Property Sheet (View -> Properties) and change the Property Values as shown below:
- Name : AsstList
- Row Source Type: Table/Query
- Row Source: SELECT Assistant.id, Assistant.asstChar FROM Assistant;
- Column Count: 2
- Column Heads: No
- Column Widths: 0";0.875"
- Bound Column: 1
- Multi-Select: None
- Left : 0.125"
- Top : 0.3125"
- Width : 1.2083"
- Height: 1.4375"
- Font Weight: Bold
- Create a Label on the top of the List Box and change the Caption to Office Assistant.
- Draw a Rectangle Control on the right side of the List Box and change the Properties as given below.
- Left: 1.4271"
- Top: 0.3125"
- Width: 1.7188"
- Height: 1.4375"
- Back Style: Transparent
- Special Effect: Sunken
- Create two Command Buttons below the List Box as shown on the Design. Display the Property Sheet of the Left Command Button. Change the Properties as given below:
- Name: cmdSetAsst
- Caption: Set as Default
- Change the properties of the right-side Command Button.
- Name: cmdCancel
- Caption: Cancel
Form Property Values.
- Now, to change the Properties of the Form, click on the left top corner of the Form (at the intersection where both the vertical and horizontal Scales meet). Display the Property Sheet, click on the All tab of the Property Sheet, if that is not the current one, and change the Property Values as given below.
- Caption: Office Assistant
- Default View: Single Form
- Scroll Bars: Neither
- Record Selectors: No
- Navigation Buttons: No
- Dividing Lines: No
- Auto Resize: Yes
- Auto Center: Yes
- Pop Up: Yes
- Modal: No
- Border Style: Dialog
- Control Box: Yes
- Min Max Buttons: None
- Close Button: Yes
- What's This Button: No
- Width: 3.3333"
- Allow Design Changes: Design View Only
- Click on the Detail Section of the Form. Display the Property Sheet, if you have already closed it, and change the Property:
- Width = 2.4271"
- Select Save from File Menu and save the Form with the name Assistant and stay in Design View, don't close the Form.
The VBA Code.
- Display the VBA Module of the Form, View -> Code. Copy and Paste the following code into the VBA Module, save and close the Form:
Dim defaultAssistant As String Dim strAsst() As String Private Const m_left As Integer = 500 Private Const m_top As Integer = 225 Private Sub AsstList_Click() Dim vID As Byte, strFileName, FRM As Form, l As Long Dim ctrl As Control On Error GoTo AsstList_Click_Exit: vID = [AsstList] With Assistant .On = True .fileName = strAsst(vID) .Animation = msoAnimationGetAttentionMajor .AssistWithHelp = True .GuessHelp = True .FeatureTips = False .Left = m_left .Top = m_top .Visible = True End With AsstList_Click_Exit: Err.Clear End Sub Private Sub cmdCancel_Click() On Error GoTo cmdCancel_Click_Exit With Assistant .On = True .fileName = defaultAssistant .Animation = msoAnimationBeginSpeaking .AssistWithHelp = True .GuessHelp = True .FeatureTips = False .Left = m_left .Top = m_top .Visible = True End With DoCmd.Close acForm, Me.Name cmdCancel_Click_Exit: Err.Clear End Sub Private Sub cmdSetAsst_Click() DoCmd.Close acForm, Me.Name End Sub Private Sub Form_Load() Dim db As Database, rst As Recordset Dim acsFiles As Integer, i As Integer On Error GoTo Form_Load_Exit defaultAssistant = Assistant.fileName acsFiles = DCount("* ", "Assistant") If acsFiles = 0 Then MsgBox "Assistants File Not found. " Exit Sub End If ReDim strAsst(1 To acsFiles) As String Set db = CurrentDb Set rst = db.OpenRecordset("Assistant", dbOpenDynaset) i = 0 Do While Not rst.EOF i = i + 1 strAsst(i) = rst![Path] rst.MoveNext Loop rst.Close With Assistant If .On = False Then .On = True End If .fileName = defaultAssistant .Animation = msoAnimationBeginSpeaking .AssistWithHelp = True .GuessHelp = True .FeatureTips = False .Left = m_left .Top = m_top If .Visible = False Then .Visible = True End If End With Form_Load_Exit: Err.Clear End Sub
Selecting the Office Assistant.
- Open the Form in Normal View. Click on the items in the List Box one by one giving a little time gap for the Assistant Character to appear. When your favorite image appears, click on the Set as Default Command Button to set the current Character as the default Office Assistant. If you change your mind then click Cancel Button to retain the existing one.
You can export this Form to your other Projects and use it to link the Microsoft Office Library File.
NB: At the beginning of the Code, I have defined two Constants m_left = 500 and m_top = 225 to position the Image on the Form when it appears based on my machine's Screen Resolution 1024 x 768. You may change this value to adjust it to your machine's Screen Resolution.
Download Demo Database
No comments:
Post a Comment
Comments subject to moderation before publishing.