How to enhance your Microsoft Access data entry forms
July 27, 2009 | 7:12 pmIf you’re new here, you may want to subscribe to my RSS feed. Thanks for visiting!
This article will offer a simple solution of how to let the person know what is needed from them on Microsoft Access data entry forms and where it is needed.
Last week I was asked for a way to give the person an on screen message while on Microsoft Access data entry forms without it requiring them to dismiss it by clicking the OK button on a message box. My reply was to have a label change it’s caption property from nothing to “The desired message…” then back to nothing using the form’s built in timer and some OnTimer event code. This article using some code similar to the last posted article. It addresses two areas of Microsoft Access data entry forms assistance. The first is a visual clue as to where that skinny little cursor is blinking and second, what the user needs to know about the current form control that has cursor focus. The first area was addressed by changing the background color to a light shade of blue as the visual clue. The second area was addressed by having a custom message appear in a label at the top of the form. The messages are stored in the Tag property of each control that requires a message to be displayed by Microsoft Access. Data entry forms might have a message that simply lets the data entry person know that this is a required field or it might supply more about the type of information that should be entered in this field. This message is turned off when the user move to the next control on the form.
Below is a short video demonstrating how this works.
This green colored code below is all you need at the form level. It is placed in the form’s On Open Event.
Private Sub Form_Open(Cancel As Integer)
Me.SetFocus
Call SetEventHandlers(Me)
End Sub
Each form control has a tag property where you can type in the message you want to appear in the ‘lblControlMsg’ label that you will need to place on your form. If you need help finding the tag property see this video.
Place code below in a code module:
Public Sub SetEventHandlers(frm As Form)
‘Runing this routine from the OnOpen event of any form using
‘Call SetValidatorEventHandlers(Me)
‘will replace any OnGotFocus and OnLostFocus event code
‘with a call to the Highlighter function.
On Error GoTo errline
Dim ctl As Control
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox
If ctl.Visible = True Then
ctl.OnGotFocus = “=Highlighter(true)”
ctl.OnLostFocus = “=Highlighter(false)”
End If
Case Else
End Select
Next
exitline:
Exit Sub
errline:
Select Case Err.Number
Case Else
MsgBox “Error ” & Err.Number & Chr(10) & Err.Description
GoTo exitline
End Select
End Sub
Public Function Highlighter(TurnOn As Boolean)
On Error GoTo errline
Select Case Screen.ActiveControl.ControlType
Case acTextBox, acComboBox, acListBox
If TurnOn Then
Screen.ActiveControl.BackColor = 16773857
‘requires that the name of the message control be labeled ‘lblControlMsg’
Screen.ActiveForm![lblControlMsg].Caption = Screen.ActiveControl.Tag
Else
Screen.ActiveControl.BackColor = -2147483643
Screen.ActiveForm![lblControlMsg].Caption = “”
End If
Case Else
End Select
exitline:
Exit Function
errline:
Select Case Err.Number
‘Form window not visible yet to see Screen.ActiveControl
‘(Only needed when setting event handlers by code)
Case 2475
Resume exitline
Case Else
MsgBox “Error ” & Err.Number & Chr(10) & Err.Description
GoTo exitline
Resume Next
End Select
End Function
Let me know how this worked for you by entering your comments and suggestions.






That’s pretty cool. Congratulations Bob. As usual, a video is worth a million words
yeh right.. great post, Thank You
Bob, Thanks for the code. Its great! and worked the first time out for me. I am using the coded to support many of the forms I developed for our boat club Data System. Because blue and light blue are dominant colors in the system forms and reports, I have used a light yellow for the lblControlMsg label Backcolor. It looks great.
I don’t understand all the code but I will study until I do. Do you have a video on error handling? It is a black hole in my understanding of visual basic.
I inserted the following remark in the code module that contains the supporting code: “This code is courtesy Bob Heifler of MyAccessProgram.com”
Thanks It was a good one!!
Steve
Bob,
What advantages does this method have over using Conditional Formatting?
-Richard
None with the later versions of Access, however it exposes those learning to these control events and additional code possibilities. I agree that for just a background color change on getting focus, the new conditional formatting is fine. This offers something fun for newbies to play with and explore on their first coding attempts.