Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Filter Function Output In Listbox-2

Introduction

Last week we saw the usage of the Filter() Function with a simple example and I hope you understood how it works. We have assigned constant values of the Source Array elements directly, to keep the VBA Code as simple as possible.

We can filter data on Forms by setting Criteria on the Filter Property of Forms. Similarly, we can use conditions in Queries to filter information from Tables as well.

But, the Filter() Function gives a unique way of filtering data from an Array of information loaded from Tables or Queries and creates output quickly based on matching or non-matching options.

Let us try out the Filter() Function in an Address Book Application to quickly find persons or places that match the specified search text and display them in a List Box. We will use Names and Addresses from the Employees Table of Northwind.mdb sample database for our experiment.

Following is the User Interface design that we planned to create and explains how the user will interact with it to display information quickly on the Form.

We will design a Form with a List Box, a Text Box Control, a Check-Box Control, and a Command Button for our experiment. An image of such a Form in Design View is given below:

When the Form is open in normal view the List Box and Text Box Controls will be empty. The User can enter the word ALL in the Text Box Control and click the Command Button to display the Name and Addresses of all Employees in the List Box.

Or

The User can enter a word or phrase, like part of a Name or Address, that can match anywhere within the Name and Address text, and click on the Command Button to filter out the matching items and to display them in the List Box.

If the Matching Cases Check-Box is in the selected state, then the Filter action will select records that match with the search text given in the Text Box Control otherwise it will select all records that do not match with the search text.

To provide the User with the above facility, we need two Subroutines on the Form's Code Module and a User Defined Function in the Standard Module of the Database to use the Filter() Function.

When the User opens the above Form the first Sub-Routine is run from the Form_Load() Event Procedure to read the data (First Name, Last Name & Address) from the Employees Table, join all the three field values in a single row of text, and load them into a Singly Dimensioned Array Variable in Memory. This data will remain in memory till the User closes the Form.

The second Sub-Routine is run when the user clicks on the Command Button to extract information from the Source Array with the help of the Filter() function, based on the search text entered into the Text Box Control.

The Filter() Function will extract the entries that match with the search text in the Text Box Control, from the Source Array Variable and save the output into the target variable xTarget. All we have to do is to take these values, format them, and insert them as Row Source Property Value to display them in the List Box.


The Address Book Project.

Let us prepare for the Address Book's Quick Find Project.

The Design Task

  1. Import Employees Table from C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb sample database.
  2. Open a new Form in Design View.
  3. Select the List Box Control from the ToolBox and draw a List Box as shown on the design above.
  4. While the List Box is in the selected state display the Property Sheet (View - - > Properties) and changes the following Property Values as given below:
    • Name = AddBook
    • Row Source Type = Value List
    • Width = 4.5"
    • Height = 1.75"
    • Font Name = Courier New
    • Font Size = 10
  5. Position the Child Label attached to the List Box above and change the Caption value to Address Book.
  6. Draw a Text Box below the List Box. Change the Name Property value of the TextBox to xFind. Position the Child Label above the Text Box and change the Caption value to Search Text/ALL.
  7. Create a Check-Box Control to the right of the Text Box. Change the Name Property of the Check-Box to MatchFlag. Change the Default Value Property to True. Change the Caption value of the child label of Matching Cases.
  8. Create a Command Button to the right of the Check-Box control. Change the Name Property Value of the Command Button to cmdFilter and the Caption Property Value to Filter.

    NB: Ensure that the Name Property Values of the above controls are given exactly as I have mentioned above. This is important because we are referencing these names in Programs.

  9. Display the Code Module of the Form (View - - >Code).
  10. Copy and paste the following Code into the Form Module:

    The VBA Code

    Option Compare Database
    Option Explicit
    Dim xSource() As Variant
    
    Private Sub Form_Load()
    Dim db As Database, rst As Recordset, J As Integer
    Dim FName As String * 12, LName As String * 12, Add As String * 20
    
    'Take the count of records
    J = DCount("*", "Employees")
    
    'redimension the array for number of records
    ReDim xSource(J) As Variant
    
    Set db = CurrentDb
    Set rst = db.OpenRecordset("Employees", dbOpenDynaset)
    'load the name and addresses into the array
    J = 0
    Do Until rst.EOF
       FName = rst![FirstName]
       LName = rst![LastName]
       Add = rst![Address]
      xSource(J) = FName & LName & Add
    rst.MoveNext
    J = J + 1
    Loop
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    End Sub
    
    Private Sub cmdFilter_Click()
    Dim x_Find As String, xlist As String, xTarget As Variant
    Dim x_MatchFlag As Boolean, J As Integer
    
    Me.Refresh
    x_Find = Nz(Me![xFind], "")
    x_MatchFlag = Nz(Me![MatchFlag], 0)
    
    'if no search criteria then exit
    If Len(x_Find) = 0 Then
      Exit Sub
    End If
        'initialize list box
        xlist = ""
        Me.AddBook.RowSource = xlist
        Me.AddBook.Requery
    
    If UCase(x_Find) = "ALL" Then
        'Take all values from the Source Array
        'Format it as listbox items
        For J = 0 To UBound(xSource())
          xlist = xlist & xSource(J) & ";"
        Next
    Else    'Call the Filter Function
        xTarget = GetFiltered(xSource(), x_Find, x_MatchFlag)
        'format the returned values as list box items
        If Len(xTarget(0)) > 0 Then
            For J = 0 To UBound(xTarget)
                xlist = xlist & xTarget(J) & ";"
            Next
        End If
    End If
        'remove the semicolon from
        'the end of the list box Value List
        If Len(xlist) > 0 Then
            xlist = Left(xlist, Len(xlist) - 1)
        End If
        'insert the list item string
        'and refresh the list box
        Me.AddBook.RowSource = xlist
        Me.AddBook.Requery
    
    End Sub
  11. Save the Form with the name Filter Form.
  12. Copy and paste the following Function into a Standard Module and save the Module:
    Public Function GetFiltered(ByRef SourceArray() As Variant, ByVal xFilterText As Variant, ByVal FilterType As Boolean) As Variant
        GetFiltered = Filter(SourceArray, xFilterText, FilterType)
    End Function
    

    Filter() Function and Filter Property of the Form.

    We cannot use the Filter() Function in the Form Module because the function name clashes with the Form Property Filter.

    We have inserted the Filter() Function in the Standard Module enveloped in User Defined Function GetFiltered() with the necessary Parameters so that we can call it from the Form Module. The first parameter to the Function is passed By Reference so that it can use the Source Array values directly.

    The Demo Runs

  13. Open the Filter Form in normal View.
  14. Enter the word ALL (in this case the Matching Cases flag has no effect) in the Text Box control and Click on the Filter Command Button.

    This action will display the Name and Addresses of all Employees from the xSource() Array loaded from the Employees Table.

  15. Enter the text Ave in the Text Box and see that the Matching Cases check box is in the selected state.
  16. Click on the Command Button.

    This time you will find that only two Employee (Nancy & Laura) names and addresses are filtered and the word Ave is appearing in their Address Lines.

  17. Remove the check-mark from the Matching Cases check box and click on the Filter Command Button again.

Now, all items except the lines with the word Ave are listed in the List Box.

If you go through the Programs that we have copied into the Form Module you can see that we have declared the xSource() Array Variable in the Global area of the Module so that we can use the data in both Sub-Routines in the Form Module.

In the Form_Load() Event Procedure, we have declared three Variables as fixed-length String Type (see the declaration line given below).

Dim FName As String * 12, LName As String * 12, Add As String * 20

When we read employee Name and Addresses into these Variables the values will be left-justified inside the Variable and the balance area of the declared size will be space filled to the right. This method will space out items at a fixed distance from each other and properly align them when displayed.

It is important that we use a Fixed Width Font, like Courier New, for the List Box display and we set this in Step-4 above.

If you click the Filter Command Button when the TextBox is empty, then the program terminates, otherwise, it calls the GetFiltered() Function and passes the parameter values.

The output Values are returned in the xTarget Array and the next steps format the Value List and display them in the List Box.

Share:

Filter Function output in ListBox

Introduction

This FILTER is not related to a Query or WHERE clause in SQL or Filter settings on a Form. It is a built-in Function. Its usage is very interesting and it is useful to quickly filter out data from an Array of information through text matching. We will use this Function to search for values across more than one field of data from a Table, extract matched items or mismatched items, as the case may be, and display them in a List Box.

The Demo Run of Filter.

But first, let us look into a simple example to understand its usage. Copy and Paste the sample VBA code given below into a Standard Module in your database:

Public Function myFilter()
Dim X(7) As Variant, Y As Variant
Dim J as Integer, msg as String

X(0) = "Strawberry Milk"
X(1) = "Chocolates"
X(2) = "Milkshake"
X(3) = "Mango Juice"
X(4) = "Icecold Milk"
X(5) = "Apple Juice"
X(6) = "Buttermilk"
X(7) = "Vanilla Icecream"

'Extract all items containing the text "milk" from Array X()
'and save the output in Array Y()
Y = FILTER(x, "milk", True, vbTextCompare)
msg = ""
For J = 0 To UBound(Y)
   msg = msg & J + 1 & ". " & Y(J) & vbCr
Next

MsgBox msg

End Function

Click anywhere within the Code and press F5 to Run the Code. The output of the function will be displayed in a MsgBox.


How It Works

Let us examine the above code closely. Variable X is dimensioned for eight elements and loaded the Array with text values.

The FILTER() Function in the statement Y = FILTER(X, "milk", True, vbTextCompare) extracts the items that match with the search text milk from the Source Array of values from Variable X and saves the output as an array of Values into Variable Y.

The FILTER() Function accepts four parameters.

The first parameter X is the Array containing the Text Values.

The second parameter value milk is the search text that is compared with each item of the array of values in variable X and if a match is found anywhere within the Array Item then extracts that item as output and adds it into an element of the target Array Variable Y.

The third parameter value True asks the Filter Function to extract the matched items as output and save them in Variable Y. When this value is set as False then the output will be items that do not contain the search text milk.

The fourth parameter asks the Filter Function to apply a specific comparison method, like Binary Comparison, Database Comparison, or Text Comparison method. Here, we have used the Text Comparison method. The third and fourth parameters are Optional.

You may try the above Code with different search text, like juice or Ice, etc.

If you look at the Variable declarations of the Code you can see that we have declared the Variable Y as a simple Variant Type and not as an Array Variable.

But, this declaration is changed by the FILTER() Function and re-dimensions as an Array automatically, depending on the output of the filter action. Every time when we run the code with different search text parameters this can be different and unpredictable too. So, we have used the UBound() Function to find the number of elements in the output Array for the For. . .Next loop to take all the items and format a string to display the output items in the MsgBox.

The Source Variable must be a singly dimensioned Array. If your search text needs to be compared with several pieces of information then join all of them together as a single string and load them into the singly dimensioned array.

The Filter() Function will not work in Code Modules of Form or Report.

Real Application Around Filter() Function

I have developed an Application around this Function for our Department Secretary to find all the Office Files with their location addresses (we have hundreds of them) that match a specific word or phrase in their Subject or Description Fields and display them in a List Box on a Form.

We will try a similar and simple example with data taken from more than one field of the Employees Table, joined together as source Array contents, and display the Filter result in a List Box. I will give details of this example in the next Article.

Till that time if you find you can use this function for some of your own tasks, you may do that. When I come out with my example you can compare yours with that and find the difference.

If you did it differently share your ideas with me so that I can learn something from you too.

Share:

Dynamic ListBox ComboBox Contents

Introduction

How about displaying different sets of un-related values in a List Box; Values in different column layouts interchangeably? Perhaps, the changeover can be with the click of a Button or based on some other action from the User.

When we create a List Box or Combo Box we are provided with three different options in MS-Access: Table/Query, Value List, or Field List to choose from in the Row Source Type Property to fill with values in them. We normally use one of these options to create a Combo Box or List Box and insert other Property Values, like Column Count, Column Widths, and Bound Column manually.

But, we can use a User Defined Function in the Row Source Type Property besides the values mentioned above to fill with Values in a List Box or Combo Box.

Even though this Function is known as a User Defined Function it is actually defined by Microsoft Access and given in the Help Documents with specific rules on how to use it with various parameter Values and VBA Code structure. All we have to do is to Copy this Code and Customize it to our specific needs.

You can get the details of this Function, by placing the insertion point in the Row Source Type Property of a List Box or Combo Box Control and by pressing the F1 key to display the Help Document. When the Help Document is open look for the Hyperlink with the description User-defined Function and clicks on it to display the details of various parameters and what they do in the Function.

We will look closely at the second example Code given in the Help Document. The VBA Code is given below and we will use it in a List Box to get a general idea of its usage.

Function ListMDBs(fld As Control, ID As Variant,  row As Variant, col As Variant,  code As Variant) As Variant
Static dbs(127) As String, Entries As Integer    
Dim ReturnVal As Variant

ReturnVal = Null
    Select Case code
        Case acLBInitialize
               ' Initialize.
            Entries = 0
            dbs(Entries) = Dir("*.MDB")
            Do Until dbs(Entries) = "" Or Entries >= 127
                Entries = Entries + 1
                dbs(Entries) = Dir
            Loop
            ReturnVal = Entries
        Case acLBOpen ' Open.
            ' Generate unique ID for control.
            ReturnVal = Timer
        Case acLBGetRowCount
            ' Get number of rows.
            ReturnVal = Entries
        Case acLBGetColumnCount
    ' Get number of columns.
            ReturnVal = 1
        Case acLBGetColumnWidth
   ' Column width.
   ' -1 forces use of default width.
            ReturnVal = -1
        Case acLBGetValue   ' Get data.
            ReturnVal = dbs(row)
        Case acLBEnd  ' End.
            Erase dbs
    End Select
    ListMDBs = ReturnVal
End Function
  1. Copy the above code into a new Standard Module in your Database and save it.
  2. Open a new Form in Design View and create a List Box on it.
  3. Click on the List Box to select it, if it is not already in the selected state.
  4. Display the Property Sheet (View - - > Properties).
  5. Insert the Function name ListMDBs in the Row Source Type Property overwriting the value Table/Query.
  6. Save the Form.
  7. Open the Form in the normal view.

A list of databases from the specified directory (check Tools - - > Options - -> General Tab for your default directory location) will appear in the List Box. A sample image of a ListBox is given below:


Taking Files List From Specific Folder

You may modify the following entry in the Program to take the listing of Word or Excel files from the default Folder or from a specific Folder.

dbs(Entries) = Dir("*.xls")

OR

dbs(Entries) = Dir("C:\My Documents\*.xls")The dbs(Entries) = Dir in the subsequent calls uses the first call parameter value "C:\My Documents\*.xls" by default and populates the String Array dbs() in the Initialize step of the Program.

This is one of the segments of the Code we can customize and use for different requirements. After the initializing phase, the Function is called repeatedly by the System to obtain other values, like Rows Count, Column Count, and others, to define the Property Values of the List Box, which we normally set manually on the List Box in design time.

The ColumnWidths, when set with the Value -1 in the Program, it gives the signal to use the Default Values set manually on the Property Sheet without change. This is useful when we need a mixed format of different column sizes when more than one column of information is displayed.

Finally, the following statements pass the List Box Source Values dbs(row) that we have created under the Initialize stage for displaying in the List Box:

Case acLBGetValue ' Get data.
ReturnVal = dbs(row)

The row holds the value for the actual number of items we have loaded into the dbs() Array of 127 elements declared initially. This value is passed to the Function through the Entries Variable in the following segment of the Code:

Case acLBGetRowCount ' Get the number of rows.
ReturnVal = Entries

The dbs Variable is declared as a Static Singly Dimensioned Array with 128 elements (0 to 127) to retain the value loaded into it in the Initialize stage when the User Defined Function ListMDBs is called repeatedly by MS-Access. In each repeated Call the required Parameter Values are automatically passed by MS-Access and we don't need to provide them explicitly. The first parameter is the name of the List Box Control. The second Parameter ID is essential, for the System to identify this one from other similar processes running, and this is set with the System Timer under the following statements:

Case acLBOpen ' Open.
' Generate a unique ID for control.
ReturnVal = Timer

The System Timer generates new values at every millisecond interval and this ensures that a unique number will always assign to this parameter as a unique Identification Value if more than one User- Defined-Function is active at the same time.

The Code parameter passes appropriate values used in the Select Case statements and uses the Returned Values to define the List Box Property Values.

Using Table Record Field Values in ListBox.

If you understood or have a general idea as to how this function works to define the contents of a List Box or Combo Box then we can go forward with the trick that I mentioned at the beginning of this Article.

Second Example with Employees Table

We will create a Copy of the above Code and modify it to create a List Box with Employees Code and First Name Values (two Columns of Values) from the Employees Table of the Northwind database.

  1. Import the Employees Table from C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb.
  2. Copy the following VBA Code into the Standard Module of your database and save the Module:
    Function ListBoxValues(fld As Control, ID As Variant, row As Variant, col As Variant, code As Variant) As Variant
        Static xList(127, 0 To 1) As String, Entries As Integer
        Dim ReturnVal As Variant, k As Integer
        Dim db As Database, rst As Recordset, recCount As Integer
    
        ReturnVal = Null
        Select Case code
            Case acLBInitialize  ' Initialize.
                Set db = CurrentDb
                Set rst = db.OpenRecordset("Employees", dbOpenDynaset)
                Entries = 0
                Do Until rst.EOF
                   For k = 0 To 1
                        xList(Entries, k) = rst.Fields(k).Value
                   Next
                   rst.MoveNext
                   Entries = Entries + 1
                Loop
                rst.Close
                ReturnVal = Entries
            Case acLBOpen                    ' Open.
                ' Generate unique ID for control.
                ReturnVal = Timer
            Case acLBGetRowCount
             ' Get number of rows.
                ReturnVal = Entries
            Case acLBGetColumnCount
       ' Get number of columns.
                ReturnVal = 2
            Case acLBGetColumnWidth    ' Column width.
               ' -1 forces use of default width.
                ReturnVal = -1
            Case acLBGetValue                ' Get data.
                ReturnVal = xList(row, col)
            Case acLBEnd                        ' End.
                Erase xList
        End Select
        ListBoxValues = ReturnVal
    End Function
  3. Open the Form in Design View with the List Box that we created earlier.
  4. Click on the List Box to select it.
  5. Display the Property Sheet (View- ->Properties).
  6. Change the Column Widths Property Value to 0.5";1.5".

    The following lines of Code say that use the values set in the Column Widths property without change:

    Case acLBGetColumnWidth ' Column width.
    ' -1 forces the use of default width.
    ReturnVal = -1

    If the value in the Column Widths property is a single value (say 1") then a multi-column List will use 1 Inch for all Columns. This may not give a nice look for values with different lengths. You may try this with different values to understand them better.

  7. Create a Command Button on the Form.
  8. Ensure that the Command Button is in the selected state and display the Property Sheet.
  9. Click on the On Click Property and select [EventProcedure] from the Drop Down control and Click on the Build (. . .) Button to open the VBA Module with the skeleton of the On Click Event Procedure.
  10. Copy and Paste the following lines of code in the middle of the Event Procedure.
    Me.List40.RowSourceType = "ListMDBs"
    Me.List40.Requery
    
  11. Change the name of the List Box (the name in Bold Letters) to match the name of your own List Box.
  12. Create another Command Button below the first one.
  13. Repeat the Procedure in Step-10 and 11 for the On Click Property of the second Command Button.
  14. Copy and Paste the following code in the middle of the On Click Event Procedure:
    Me.List40.RowSourceType = "ListBoxValues"
    Me.List40.Requery
    
  15. Change the name of the List Box (the name in Bold Letters) in the Code to match with the name of your own List Box.
  16. Save and Close the Form.
  17. Open the Form in Normal View.

    Since you have already inserted the ListMDBs User Defined Function in Row Source Type Property earlier the list of databases will appear in the List Box first.

  18. Click on the second Command Button to change the List Box contents to the Employees List.

    A sample image of the List Box with Employee List is given below:

  19. Click on the first Command Button to change the List Box Contents back to the Database List again.

It works for Combo Boxes in the same way. You may create a Combo Box control and run the same functions from the Row Source Type Property.

Don't forget to set the Default Value Property with the value 1, otherwise, the Combo Box may not show anything in its Text Box area before you select an item from the list.

Share:

Office Assistant And Msgbox Menus-3

After Clickable Menu Options - Access 2003.

After going through the earlier Articles on this subject I hope that the Readers are now familiar with programming the Balloon Object of Microsoft Office Assistant. You have seen that you can use this feature with a few lines of customizable VBA Code to display MsgBox text formatted with Color, underline, and with your favorite images on them. We can display Menus on them to obtain responses from Users, besides the buttons that we normally use like OK, Cancel, Yes, No, etc.

Since this article is the third part of this series I suggest that new Readers may go through the earlier Documents on this subject to learn interesting and simple ways to use this feature in MS-Access before continuing with this Article. Links to those Articles are given below:

Last week we learned how to display Clickable Menu Options in Message Box with the use of Office Assistant. The Image of that example is given below.

We have displayed the Menu Options in the Message Box with the Labels Property of the Balloon Object of Office Assistant.

Check Box Menu Options

Here, we will learn how to display Menu Options with Checkboxes and how responses from the User can be obtained, examined, and execute actions that are programmed for each choice made. The example code and the sample image of MsgBox that displays the Check-Box Menu is given below:

Public Function ChoicesCheckBox()
Dim i As Long, msg As String
Dim bln As Balloon, j As Integer
Dim selected As Integer, checked As Integer

Set bln = Assistant.NewBalloon
With bln
    .Heading = "Select Data Output Option"
    .Checkboxes(1).text = "Print Preview."
    .Checkboxes(2).text = "Export to Excel."
    .Checkboxes(3).text = "Datasheet View."
    .Button = msoButtonSetOkCancel
    .text = "Select one of " & .Checkboxes.Count & " Choices?"
    i = .Show

    selected = 0
    If i = msoBalloonButtonOK Then
        'Validate Selection
        For j = 1 To 3
            If .Checkboxes(j).checked = True Then
                selected = selected + 1
                checked = j
            End If
        Next

       'If User selected more than one item
        'then re-run this program and force the
        'User to select only one item as suggested
        'in the message text.

        If selected = 0 or selected > 1 Then
           Call ChoicesCheckBox
        Else
            Select Case checked
                Case 1
                    Debug.Print .Checkboxes(checked).text
                Case 2
                    Debug.Print .Checkboxes(checked).text
                Case 3
                   Debug.Print .Checkboxes(checked).text
            End Select
        End If
    End If
End With

End Function

Like the Labels Property Array, the dimension of CheckBoxes also can be up to a maximum of five elements only.

In our earlier example, we have not used the OK or Cancel buttons along with the Labels based Menu because the Balloon Button (msoBalloonTypeButtons) based options were clickable and accepted the clicked item as a valid response and dismisses the Office Assistant on this action. The clicked item's index number is returned as the response value and it was easy to check this value and execute the action accordingly.


But in the case of Checkboxes, this is a little more complex because of the following reasons

  1. The CheckBoxes can be either in checked or in the unchecked state, which needs to be validated.
  2. The User may put check marks on one or more Options at the same time. If this cannot be allowed, then there must be a validation check and force the User to make the selection of one item only.
  3. If the User has the option of selecting more than one item then the program must be written to execute more than one action based on the combination of selections made.
  4. In either case, we have to inspect the checked or unchecked state of each element of the CheckBox Array to determine the validity of Menu selection.

Validating the Checked/Unchecked Items

In the example code given above the User can select only one item at a time.

  • In the validation check stage of the code, first, we are checking whether the User has clicked the OK Button or not.
  • If she did then in the next step we take a count of all check-marked items, in the Variable selected.
  • If the value in the Variable selected is zero (The User clicked the OK Button without selecting any option from the list) or selected more than one item then the Program is called again from within the ChoicesCheckBox() Function itself. This will refresh the Menu, removes the check marks, and display it again. This will force the user to make only one selection as suggested in the message or she can click Cancel Button.
  • In the next step, the action is programmed based on the selection made by the User.
  • If the User is allowed to put check marks on more than one item (depending on the purpose of the MessageBox-based Menu) then the validation check and the execution of actions can be different and the code must be written accordingly.

The methods which I have introduced to you and explained in these three Articles are good to learn the basics of this feature and easy to understand the usage of different Properties of Balloon Object of Office Assistant.

But, you will appreciate the fact that duplicating and customizing these Codes everywhere in your Programs for different needs is not advisable. This will increase the size of your database, no flexibility in usage of Code and it is not good programming practice either.

You may go through the Articles (links are given below) published earlier on this Subject that it shows, how to define Public Functions like MsgOK(), MsgYN(), MsgOKCL(), and others with the use of Office Assistant. It simplifies the usage of this feature, without duplicating the code, and can use them freely anywhere in your Programs like MS-Access MsgBox() Function.

The above Function Names themselves suggest what kind of Buttons will appear in the Message Box when they are called with the minimum Parameter Value of Message Text alone or Message Text and Title Values.

  1. Message Box using Office-Assistant
  2. Message Box with Options Menu
  3. Office Assistant with CheckBox Menu

A comparison of the above User Defined Function usage with the MsgBox is given below for reference. The underscore character in the text indicates the continuation of lines and should not be used when all values are placed on the same line.

MS-Access MsgBox() usage Office-Assistant-based User Defined Function usage
MsgBox "Welcome to Tips and Tricks"MsgOK "Welcome to Tips and Tricks"
X = MsgBox("Shut Down Application", vbQuestion+vbDefaultButton2+vbYesNo, _"cmdClose_Click()")X = MsgYN("Shut Down Application", _ "cmdClose_Click()")
X = MsgBox( "Click OK to Proceed or Cancel?", _ vbOKCancel+vbDefaultButton2+vbQuestion, _ "MonthEndProcess()")X = MsgOKCL("Click OK to Proceed or Cancel?", _
"MonthEndProcess()")

Share:

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

Forms Functions How Tos MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation Event Graph Charts ImageList Control List Boxes TreeView Control Command Buttons Controls Data Emails and Alerts Form Custom Functions Custom Wizards DOS Commands Data Type Key Object Reference ms-access functions msaccess functions msaccess graphs msaccess reporttricks Command Button Report msaccess menus msaccessprocess security advanced Access Security Add Auto-Number Field Type Form Instances ImageList Item Macros Menus Nodes RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup database function msaccess wizards tutorial Access Emails and Alerts Access Fields Access How Tos Access Mail Merge Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting ChDir Color Palette Common Controls Conditional Formatting Data Filtering Database Records Defining Pages Desktop Shortcuts Diagram Disk Dynamic Lookup Error Handler External Filter Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Message Box Monitoring Octal Numbers Operating System Paste Primary-Key Product Rank Reading Remove Rich Text Sequence SetFocus Summary Tab-Page Union Query User Users Water-Mark Word automatically commands hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar updating upload vba code