By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,948 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,948 IT Pros & Developers. It's quick & easy.

How to Handle AllowAutoCorrect for Form Controls

Expert Mod 15k+
P: 31,769
I don't have the time now to write up a proper article on this but I just had to develop this code so I thought I'd share it.

It's to handle turning off of .AllowAutoCorrect. This is often the cause of users having difficulties trying to enter data and noticing later (or not sometimes even) that what they thought they'd typed isn't what was saved.

The code below displays all forms and, within each, any controls that have .AllowAutoCorrect set to True. An optional parameter, blnFix, allows the caller to request that all occurrences are fixed to disallow this feature.

NB. There is also an application level option that allows this to be disabled, but not every developer has full control of all their users' application options so this can prove useful anyway.
Expand|Select|Wrap|Line Numbers
  1. 'AutoCorrupt() Prints off every form control that has AutoCorrect set to True.
  2. Public Sub AutoCorrupt(Optional ByVal blnFix As Boolean = False)
  3.     Dim blnAC As Boolean
  4.     Dim lngSave As Long
  5.     Dim ctlVar As Control
  6.     Dim aoVar As AccessObject
  8.     For Each aoVar In CurrentProject.AllForms
  9.         Call DoCmd.OpenForm(FormName:=aoVar.NAME _
  10.                           , View:=acDesign _
  11.                           , WindowMode:=acHidden)
  12.         With Forms(aoVar.NAME)
  13.             Debug.Print "@"; aoVar.NAME;
  14.             lngSave = acSaveNo
  15.             For Each ctlVar In .Controls
  16.                 On Error Resume Next
  17.                 blnAC = ctlVar.AllowAutoCorrect
  18.                 On Error GoTo 0
  19.                 If blnAC Then
  20.                     Debug.Print "~"; ctlVar.NAME;
  21.                     If blnFix Then
  22.                         ctlVar.AllowAutoCorrect = False
  23.                         lngSave = acSaveYes
  24.                     End If
  25.                     blnAC = False
  26.                 End If
  27.             Next ctlVar
  28.         End With
  29.         Call DoCmd.CLOSE(ObjectType:=acForm _
  30.                        , ObjectName:=aoVar.NAME _
  31.                        , Save:=lngSave)
  32.     Next aoVar
  33. End Sub
NB. The name is not a typo in this case.
May 7 '15 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 5,397
Never thought of that... thank you!
May 11 '15 #2

Expert Mod 15k+
P: 31,769
Always a pleasure :-)
May 14 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.