为此,红尘老师的几个版本都有相应的解决方案,但都未解决彻底。
刚开始的版本解决方法是:在“modCalendar”模块中加入了“If DateInputCtl.Locked Then Exit Function”一句,解决了第一个问题,但没有解决第2个问题。
在2010-12-11更新的附件中,反而去掉了这一句,改而在“frmCalendar”窗体中加入了
Function SetDateValue()
On Error Resume Next
If Not g_txtDateInput Is Nothing Then
If g_txtDateInput.Enabled And (Not g_txtDateInput.Locked) And g_txtDateInput.Parent.AllowEdits Then
g_txtDateInput = Me.txtDate
End If
End If
Call cmdCancel_Click
End Function
之前我试过多种方法,在“If DateInputCtl.Locked Then Exit Function”一句后再加上:
1) If Screen.ActiveForm.Form.AllowEdits = False Then Exit Function
2) If DateInputCtl.Parent.AllowEdits = False And Not DateInputCtl.Parent.NewRecord Then Exit Function
3) If Screen.ActiveControl.Parent.AllowEdits = False Then Exit Function
后来我选定了第2种方法,一直没问题,直到在选项卡中使用出现了我贴子所提出的问题。经测试,在选项卡中使用,不能使用“.Parent.AllowEdits ”方法,这也是红尘2010-12-11改进版存在同样问题的原因所在。所以就我只能改用第一种方法了,测试后正常,问题就此解决。
哎,好事多磨。
再试了一下,在“If DateInputCtl.Locked Then Exit Function”一句后再加上:
If Screen.ActiveForm.Form.AllowEdits = False Then Exit Function
在目标控件在选项卡,或主窗体中时,使用是正常的,
但当目标控件在子窗体中时,If Screen.ActiveForm.Form.AllowEdits = False Then Exit Function这一句仍无效,Screen.ActiveForm.Form指的是主窗体,被禁止编辑的子窗体仍能能够输入日期,同时将子窗体属性“被”改为了允许编辑。
最后再试,不能使用=CalendarFor([txtPrintDate])方法,
只能使用VBA代码,在单击或双击事件中加入:
If Me.AllowEdits = True Then CalendarFor Me.txtPrintDate