F
Fysh
I posted several times here about a program that I am developing. I am
usually able to solve my problems after a few tries of different options.
However, this time I am a little stuck and could use some assistance. The
following is some code that is called after 3 combo boxes are checked to see
if the are not null. This all works fine and dandy. My problem is with my
subform. The subform is unbound with several check boxes and labels in a
column format all which are unbound as well. What I am exeriencing is if the
user needs to change one of the check boxes to either yes or no and then they
decides to change one of the options from the combo box it should reset the
subform instead I keep getting an error. If I don't edit the subform and
change the selection from any of the combo boxes then the subform updates
properly it is only when I make a change on the subform then try to make a
different selection. The error message is Run time error 2164 You can't
disable a control while it has the focus. Can anyone assist on this? I
tried several options, but none seem to work. Thanks in advance.
Private Function UpdatefrmPracticalSubform()
Dim dbs As Database
Dim rst As Recordset
Dim varX As Integer
Dim varC As Variant
DoCmd.SetWarnings False
DoCmd.OpenQuery "qrySetupFormTemp"
DoCmd.SetWarnings True
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSetupTemp")
If rst.RecordCount >= 0 Then
varX = rst.RecordCount
For k = 1 To varX
If Forms!frm1.frm2.Form("chk" & k).Visible = True Then
Forms!frm1.frm2.Form("chk" & k).Undo
End If
varC = DLookup("Category", "tblCategory", "CATID= " &
rst![CATID])
Forms!frm1.frm2.Form("chk" & k).Visible = True
Forms!frm1.frm2.Form("lbl" & k) = varC
If rst![Required] = True Then
Forms!frm1.frm2.Form("chk" & k) = True
Else
Forms!frm1.frm2.Form("chk" & k) = False
End If
If rst![Enabled] = True Then
Forms!frm1.frm2.Form("chk" & k).Enabled = True
Else
Forms!frm1.frm2.Form("chk" & k).Enabled = False
End If
rst.MoveNext
Next k
rst.Close
End If
For j = varX + 1 To 20
If Forms!frm1.frm2.Form("chk" & k).Visible = True Then
Forms!frm1.frm2.Form("chk" & k).Undo
End If
Forms!frm1.frm2.Form("lbl" & j) = Null
Forms!frm1.frm2.Form("chk" & j).Enabled = False
Forms!frm1.frm2.Form("chk" & j).Visible = False
Next j
If varX > 10 Then
Forms!frm1.frm2.Form.ScrollBars = 2
Else
Forms!frm1.frm2.Form.ScrollBars = 0
End If
Forms!frm1.frm2.Form.Requery
Forms!frm1.frm2.Form.Visible = True
Me.Label1.Visible = True
End Function
usually able to solve my problems after a few tries of different options.
However, this time I am a little stuck and could use some assistance. The
following is some code that is called after 3 combo boxes are checked to see
if the are not null. This all works fine and dandy. My problem is with my
subform. The subform is unbound with several check boxes and labels in a
column format all which are unbound as well. What I am exeriencing is if the
user needs to change one of the check boxes to either yes or no and then they
decides to change one of the options from the combo box it should reset the
subform instead I keep getting an error. If I don't edit the subform and
change the selection from any of the combo boxes then the subform updates
properly it is only when I make a change on the subform then try to make a
different selection. The error message is Run time error 2164 You can't
disable a control while it has the focus. Can anyone assist on this? I
tried several options, but none seem to work. Thanks in advance.
Private Function UpdatefrmPracticalSubform()
Dim dbs As Database
Dim rst As Recordset
Dim varX As Integer
Dim varC As Variant
DoCmd.SetWarnings False
DoCmd.OpenQuery "qrySetupFormTemp"
DoCmd.SetWarnings True
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblSetupTemp")
If rst.RecordCount >= 0 Then
varX = rst.RecordCount
For k = 1 To varX
If Forms!frm1.frm2.Form("chk" & k).Visible = True Then
Forms!frm1.frm2.Form("chk" & k).Undo
End If
varC = DLookup("Category", "tblCategory", "CATID= " &
rst![CATID])
Forms!frm1.frm2.Form("chk" & k).Visible = True
Forms!frm1.frm2.Form("lbl" & k) = varC
If rst![Required] = True Then
Forms!frm1.frm2.Form("chk" & k) = True
Else
Forms!frm1.frm2.Form("chk" & k) = False
End If
If rst![Enabled] = True Then
Forms!frm1.frm2.Form("chk" & k).Enabled = True
Else
Forms!frm1.frm2.Form("chk" & k).Enabled = False
End If
rst.MoveNext
Next k
rst.Close
End If
For j = varX + 1 To 20
If Forms!frm1.frm2.Form("chk" & k).Visible = True Then
Forms!frm1.frm2.Form("chk" & k).Undo
End If
Forms!frm1.frm2.Form("lbl" & j) = Null
Forms!frm1.frm2.Form("chk" & j).Enabled = False
Forms!frm1.frm2.Form("chk" & j).Visible = False
Next j
If varX > 10 Then
Forms!frm1.frm2.Form.ScrollBars = 2
Else
Forms!frm1.frm2.Form.ScrollBars = 0
End If
Forms!frm1.frm2.Form.Requery
Forms!frm1.frm2.Form.Visible = True
Me.Label1.Visible = True
End Function