Allow Edits not letting me use Combo Box

G

Gina Whipp

Hello All,

I have the below code on current. Works great only I can't use the combo
box to look up another coil as it to won't allow edits. I have tried
putting Allow Edits = True in the OnClick event to no avial and can't use
the Get Focus event as it is the first field the form goes to on open. Any
ideas as to what I can do to lock the form, if Status = C but leave the
combo box unlocked. (Oh, no subforms) Thanks for any help ypu can give me.

If (Me.txtStatusID) = "C" Then
Me.txtCoilMessage = "Coil Complete"
'Me.Caption = "Coil Receipt Completed Coil VIEW ONLY!"
Me.AllowEdits = False
Else
Me.txtCoilMessage = " "
'Me.AllowEdits = True
End If


Thanks,
Gina Whipp
 
D

Dirk Goldgar

Gina Whipp said:
Hello All,

I have the below code on current. Works great only I can't use the
combo box to look up another coil as it to won't allow edits. I have
tried putting Allow Edits = True in the OnClick event to no avial and
can't use the Get Focus event as it is the first field the form goes
to on open. Any ideas as to what I can do to lock the form, if
Status = C but leave the combo box unlocked. (Oh, no subforms)
Thanks for any help ypu can give me.

If (Me.txtStatusID) = "C" Then
Me.txtCoilMessage = "Coil Complete"
'Me.Caption = "Coil Receipt Completed Coil VIEW ONLY!"
Me.AllowEdits = False
Else
Me.txtCoilMessage = " "
'Me.AllowEdits = True
End If


Thanks,
Gina Whipp

Set the Locked property of all the individual controls you want to keep
the user from editing. If it's not many, you can just list them by
name. Or you can use a function like this:

'----- start of code -----
Public Function fncLockUnlockControls(frm As Form, LockIt As Boolean)

' Lock or unlock all data-bound controls on form <frm>,
' depending on the value of <LockIt>: True = lock; False = unlock.

On Error GoTo Err_fncLockUnlockControls

Const conERR_NO_PROPERTY = 438

Dim ctl As Control

For Each ctl In frm.Controls

With ctl
If Left(.ControlSource & "=", 1) <> "=" Then
.Locked = LockIt
End If
End With
Skip_Control: ' come here from error if no .ControlSource property
Next ctl

Exit_fncLockUnlockControls:
Exit Function

Err_fncLockUnlockControls:
If Err.Number = conERR_NO_PROPERTY Then
Resume Skip_Control
Else
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_fncLockUnlockControls
End If

End Function

'----- end of code -----

The function will lock or unlock all bound controls, but leave unbound
and calculated controls alone. So you could write:

If (Me.txtStatusID) = "C" Then
Me.txtCoilMessage = "Coil Complete"
'Me.Caption = "Coil Receipt Completed Coil VIEW ONLY!"
fncLockUnlockControls Me, True
Else
Me.txtCoilMessage = " "
fncLockUnlockControls Me, False
End If
 
G

Gina Whipp

Thanks Dirk, I'll give the coding part a try, too many controls to start
listing seperately!
 

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