Posted this on Mr Excel/Access forum a while ago with no response so hoping someone here can help.
My Access 2010 developed database has a problem when a particular form is switched to Design View from Form View when running under Access 2013. I get an "MS Access has Stopped Working" error message and Access closes & restarts. I have narrowed it down to some VBA code, part of which, if eliminated, removes the problem. Everything else in the dbase appears to work. The entire module is:
By trial and error, I have found that commenting out the "Set cTextBox = c" and "Set cComboBox = C" statements removes the problem (I then get a VBA execution error message, not surprisingly I guess, but the Access Stopped Working error is gone).
I didn't write the code and I'm not sure what it is doing at some of the code level but it appears Access 2013 doesn't like it for some reason. Could someone please offer a suggestion as to how to get this to work with 2013? Please excuse the poor code formatting - the "
My Access 2010 developed database has a problem when a particular form is switched to Design View from Form View when running under Access 2013. I get an "MS Access has Stopped Working" error message and Access closes & restarts. I have narrowed it down to some VBA code, part of which, if eliminated, removes the problem. Everything else in the dbase appears to work. The entire module is:
Code:
Option Compare Database
Option Explicit
Private WithEvents cTextBox As TextBox
Private WithEvents cComboBox As ComboBox
Private colFrmControls As Collection
Public Sub CFInitialize(Frm As Form)
Dim c As Control
Dim cCF As clsControlFocus
Set colFrmControls = New Collection
For Each c In Frm.Controls
Select Case c.ControlType
Case acTextBox, acComboBox
If c.Enabled And c.Visible Then
Set cCF = New clsControlFocus
Set cCF.ControlSetting = c
colFrmControls.Add cCF
End If
End Select
Next c
End Sub
Public Property Set ControlSetting(ByVal c As Control)
Select Case c.ControlType
Case acTextBox
Set cTextBox = c
cTextBox.OnEnter = "[Event Procedure]"
cTextBox.OnLostFocus = "[Event Procedure]"
Case acComboBox
Set cComboBox = c
cComboBox.OnEnter = "[Event Procedure]"
cComboBox.OnLostFocus = "[Event Procedure]"
End Select
End Property
Private Sub cTextBox_Enter()
OnEnterSettingsTextBox cTextBox
End Sub
Private Sub cTextBox_LostFocus()
OnLostFocusSettingsTextBox cTextBox
End Sub
Private Sub cComboBox_Enter()
OnEnterSettingsComboBox cComboBox
End Sub
Private Sub cComboBox_LostFocus()
OnLostFocusSettingsComboBox cComboBox
End Sub
Private Sub OnEnterSettingsTextBox(c As Control)
With c
.BackColor = RGB(255, 255, 255) 'while
.ForeColor = RGB(0, 0, 0) 'black
End With
End Sub
Private Sub OnLostFocusSettingsTextBox(c As Control)
With c
.BackColor = RGB(214, 223, 236) 'bluish
.ForeColor = RGB(0, 0, 0) 'black
End With
End Sub
Private Sub OnEnterSettingsComboBox(c As Control)
With c
.BackColor = RGB(255, 255, 255) 'white
.ForeColor = RGB(0, 0, 0) 'black
End With
End Sub
Private Sub OnLostFocusSettingsComboBox(c As Control)
With c
.BackColor = RGB(214, 223, 236) 'bluish
.ForeColor = RGB(0, 0, 0) 'black
End With
End Sub
I didn't write the code and I'm not sure what it is doing at some of the code level but it appears Access 2013 doesn't like it for some reason. Could someone please offer a suggestion as to how to get this to work with 2013? Please excuse the poor code formatting - the "
Code:
" tags seem to remove certain blank lines and add others.
TIA for any help...