Trouble resetting subform after update

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
 
F

Fysh

Once again never mind, figured it out. I am sorry for continuing to post
only to solve the problem later. I just had to change the focus to something
else on the subform after checking the box. Once again sorry you had to read
this post. I still don't quite understand if I check something on the main
form doesn't the main form have the focus at that time?

Fysh said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top