Category Archives: MS Access Forms

MS Access Forms

MS Access Reserved Word Checker

If you aren’t already aware of it, there are a set of words which should never be used to name

  • Database objects (Tables, Queries, Forms, …)
  • Table/Query Fields
  • Form/Report Controls
  • VBA procedure names, variable, …

these are referred to as Reserved Words and thus Reserved Words need to be avoided at all cost as they can generate strange behaviors or outright failure of your database.

There are numerous examples of oddities caused by Reserved Words, but below is one of them as an example:

 

The issue with Reserved Words is that there is simply no way to remember them all.  Furthermore, when taking over another developer’s work, it is next to impossible to review every object, control, … for such terms.

Continue reading

Great Access Tools – Calendar Controls

Those of you that follow this blog or have seen my forum posts regarding the built-in date picker know my thoughts on the matter.  To put it simply, it is a disgrace that this is what Microsoft supplied with Access for selecting dates.  If you want more reasons as to why I think this, refer to my earlier post

 

So, since I highly recommend completely disabling the built-in date picker and replacing it, I thought I should show a couple of the excellent replacements.

Also, another reason to implement a date picker and stop manual entry by your users is to avoid formatting issues depending on what format the user chose to use when inputting the date.  06/11/11, what’s the day, month and year?  No guarantee Access will save it as was intended by the users.  However, by using a date picker, you have 100% certainty that the date entered is the date saved!

Continue reading

Great Access Tools – Treeview Control

Like many of you, I have used the TreeView control in the past for a couple projects.  Sadly, everything came crashing down on me when Microsoft released their update KB2596856 and instantaneously my clients who were running my databases with the TreeView control could work no longer! … I cleaned up the mess and stayed as far away from ActiveX controls as possible.

On top of that, it never got ported to x64 bit, so those developers were screwed (for lack of a better word).

Then Microsoft decided to do away with the TreeView control altogether.

So what does one do?

The TreeView itself can be a very useful tool no doubt, but Microsoft’s solution was too limited and fragile.

Once again, the community answered the call!  JKP Application Development Services developed and freely released 100% VBA TreeView, no strings attached!

Continue reading

MS Access – Find Macros Using a Search Term

To continue my original post, entitled MS Access – Find Embedded Macros, regarding identifying where Embedded Macro were being used within an Access database, I also develop the following procedure that enable one to search through all Embedded Macros and Standard Macros for a search term. The search term can be anything, object names, commands, segments of words, …

I originally was using this to identify where Forms were being called since I needed to rename them.

Continue reading

MS Access – Find Embedded Macros

Most people already know that I do not favor Embedded Macros in any capacity. Unlike VBA, Macros are more complicated to program, are not searchable making it hard to perform database updates.

Long story short, I was working on a project a short while ago where I need to do a major cleanup of object names, control names, … and was needing to identify where object were being used so I could update them. Then I decided, even better, let’s find all the Embedded Macros so I can simply convert them over to plain VBA and then this problem would not occur again in the future.

As such, I put together the following procedure which goes through all the database Forms and Reports and their respective controls to identify those that use Embedded Macros. Hopefully it can help someone else.

Continue reading

Access Dynamic Datasheet Charts

Ever wanted to base a chart off of a datasheet and have the chart automatically updated based on whatever filters the user may apply?

I did!

I started off doing some Googling and was surprised to find nothing on the subject.

Then I turned to my fellow MVPs for guidance and was surprised that this seemed to be an unusual request. With a little back and forth I managed to put together a functional approach.

Continue reading

Great Access Tools – Access Crash Reporter

I’m starting a series of posts to promote some great tools to be aware of as an Access developer

Today, I’d like to introduce you to TheSmileyCoder’s Access Crash Reporter.

Any developer can attest that errors will occur and quite often users do not jot down the details of exactly what happened exactly thus making it very difficult to troubleshoot at times.  The Access Crash Reporter is a tool through which you can collect error data so you don’t have to solely rely on the users account of the problem.

This free tool gathers a tremendous amount of information:

  • Error Source
    • Object
    • Control
    • Parent Object (if applicable)
  • User
  • OS Information
  • Access Information
  • and so much more!

about errors when they occur and can, amongst other things:

  • Log errors to a tables
  • Generate E-mails to notify the contact of your choosing when error occur supplying them with all the details, a Screenshot of the application and of the object involved

TheSmileyCoder has a 7 minute video on his site, or view it directly on YouTube by using the following link: Crash Report Tool – Demo, Setup and Instructions which briefly demonstrates the tool and the resulting error collection, e-mail, …

If you don’t have an error handling system yet, consider taking this one for a test drive. If you are new to the subject of Error Handling, you may also like to review my article MS Access – VBA – Error Handling.

If you do have a error handling system, consider taking this one for a test drive.  It truly adds some nice functionalities and makes error reporting much more user-friendly.

Note
I have no affiliation with above mentioned website, developer, product, company … The above is an independent, unsolicited post based on my personal opinion.

Update 2024-05-04: Since TheSmileyCoder’s site no longer exists, I have updated the links to point to an archived version of his site.

MS Access VBA – Set Form’s GridX and GridY Properties

One thing I find when taking over projects from various sources, especially when the database has already been through the hands of several developers is that many default properties can be all different depending on the object types and who create/worked on them. As such, one can spend a lot of time trying to open each form and clean things up. Things like:

  • Date Picker
  • Record Locking
  • Background Colors
  • Alternate Background Colors (for continuous forms)
  • GridX and GridY

As such, I created a very straightforward function that you can run to apply a standard GridX and GridY value to all your forms in once shot.

'---------------------------------------------------------------------------------------
' Procedure : SetFrmsGridProp
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Loops through all the database forms to set the GridX and GridY properties
'               great way to quickly set a common value to all your forms
' Copyright : The following is release as Attribution-ShareAlike 4.0 International
'             (CC BY-SA 4.0) - https://creativecommons.org/licenses/by-sa/4.0/
' Req'd Refs: Uses Late Binding, so none required
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' iGridX    : New GridX value to set
' iGridY    : New GridY value to set
'
' Usage:
' ~~~~~~
' Call SetFrmsGridProp(20, 20)
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2015                    Initial Release
' 2         2018-09-20              Updated Copyright
'---------------------------------------------------------------------------------------
Public Sub SetFrmsGridProp(iGridX As Integer, iGridY As Integer)
    On Error GoTo Error_Handler
    Dim db                    As Object
    Dim obj                   As AccessObject
    Dim frm                   As Access.Form
    Dim i                     As Long
    
    Set db = Application.CurrentProject
    For Each obj In db.AllForms
        i = i + 1
        DoCmd.OpenForm obj.Name, acDesign
        Set frm = Forms(obj.Name).Form
        frm.GridX = iGridX
        frm.GridY = iGridY
        DoCmd.Close acForm, obj.Name, acSaveYes
    Next obj

Error_Handler_Exit:
    On Error Resume Next
    Set frm = Nothing
    Set obj = Nothing
    Set db = Nothing
    Exit Sub

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: SetFrmsGridProp" & vbCrLf & _
           "Error Description: " & Err.Description & _
           Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub

Obviously, this could be adapted to be applied to Reports as well with one minor tweak of the code.

Disable the MS Access Date Picker

I won’t lie, I hate the built-in MS Access Date Picker. Once again, Microsoft did things as poorly as possible by implementing the most primitive Date Picker possible. One that only moves forwards or backwards one month at a time. No Month selector. No Year selector. No ability to interact with it through VBA!

MS Access Date Picker

Try using the built-in Date Picker to enter someone’s birthdate. For instance, try using it to enter April 1st, 1941. I hope you have some time on your hands as you’re going to have to click on the past month button 907 TIMES!!!

With a great many available Date Pickers to inspire themselves with/from, I still cannot remotely grasp how this one was adopted. We’re supposed to facilitate the end-user’s jobs by simplifying data entry, not making their lives a living nightmare.

Okay, enough with the rant, let’s move forward and see how we can actually help our users! The reality is that the best thing we can do is adopt one of many form based date pickers like one of the numerous ones I listed in my post: https://www.devhut.net/2017/06/17/great-access-tools-calendar-controls/.

That said, we have to first disable the built-in Date Picker from always displaying (possibly overtop of our calendar button). Now, we can open each form individually and then edit the Show Date Picker property of each date control, but this is time consuming and one can easily overlook a control or two. As such, I set out to find a better way than having to manually edit individual form control properties and knew that we could harvest the power of VBA to rescue us from this Date Picker affliction.

As such, I put together the following code which iterates through all the forms, and all the controls within each form to change the property (sadly, there is no global database setting and it has to be set control by control!).

'---------------------------------------------------------------------------------------
' Procedure : disableDatePicker
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Disable the built-in date picker in all the database forms.  This is to
'             avoid issue with using the calendar form that we have chosen to implement.
' Copyright : The following may be altered and reused as you wish so long as the
'             copyright notice is left unchanged (including Author, Website and
'             Copyright).  It may not be sold/resold or reposted on other sites (links
'             back to this site are allowed).
'
' Usage:
' ~~~~~~
'
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2011-Oct-09                 Initial Release
'---------------------------------------------------------------------------------------
Sub DisableDatePicker()
    On Error GoTo Error_Handler
    Dim ctl             As Access.Control
    Dim frm             As AccessObject

    For Each frm In CurrentProject.AllForms
        DoCmd.OpenForm frm.Name, acDesign

        For Each ctl In Forms(frm.Name).Form.Controls
            Select Case ctl.ControlType
                Case acTextBox
                    ctl.ShowDatePicker = 0
            End Select
        Next ctl

        DoCmd.Close acForm, frm.Name, acSaveYes
    Next frm

Error_Handler_Exit:
    On Error Resume Next
    Set ctl = Nothing
    Set frm = Nothing
    Exit Sub

Error_Handler:
    MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: DisableDatePicker" & vbCrLf & _
           "Error Description: " & Err.Description, _
           vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub

This is now one of the first procedures that I run on databases that I take over as part of my cleanup routine. Hopefully it can help other too!