Lock single records on form set to Continuous Records Default View

G

Guest

Hello,

I have the following code behind a checkbox on my form that is set to
'Continuous Records' for its Default View with the thought that I can lock
the current record once the checkbox is checked and then proceed to enter
subsequent records. I thought I had it working, but checking it now, it is
not. Here is the code:

Private Sub record_monitored_AfterUpdate()
On Error Resume Next
Dim ctl As Control
Dim frm As Form
Dim LockValue As Boolean
'If MsgBox("Checking the Monitored Box will lock this record. Is this OK?",
vbYesNo) = vbYes Then
For Each ctl In frm.Controls
With ctl

Select Case .ControlType
Case acTextBox
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acComboBox
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acListBox
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acCheckBox
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acToggleButton
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acCommandButton
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acSubform
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acOptionGroup
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

Case acOptionButton
If Forms!fIndepConcomMeds!record_monitored <> 0 Then
ctl.Locked = LockValue
Else
ctl.Locked = False
End If

End Select
End With
Next ctl
Set ctl = Nothing
Set frm = Nothing
'End If
End Sub

When I get to the ' Select Case .ControlType' line using the Debugger, it
immediately skips all the way down to 'End Select', and soon then to 'End
Sub', so none of the controls in the current record are locked.

Why is it skipping directly to the 'End Select'? I do have similar code in
the Form's 'On Current' Event as well, and am not sure if this is interfering.

Thank you.
 
G

Guest

Pat,

Although you defined frm as a form, you never set it to anything. Try
inserting this just before the For Each loop.

Set frm = me

Is there a reason that your are refering to Forms!fIndepConcomMeds rather
than to frm or me? Is this another form that is open at the same time?

In this case, I would also get rid of the With ctrl and End With and replace
most of your code with this condensed version:

For Each ctl in frm.Controls

Select case ctl.ControlType
Case acTextBox, acComboBox, acListBox, acCheckBox, acToggleButton, _
acCommandButton, acSubForm, acOptionGroup, acOptionButton
ctl.Locked = frm.record_Monitored
Case Else
debug.print ctl.name, ctl.ControlType
End Select

Next ctl
set ctl = nothing
set frm = nothing

HTH
Dale
 

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