Can't stop user from editing form

T

thesizz

I’m having a problem getting the AllowEdits property to work.

Here is the issue. I have a form - frmOrders . The forms Form_Current event
has the following line of code:

AllowEdits = False

This works fine and when the user tries to edit a field on the form he is
unable to. However, if the user clicks in or enters the control cboLookup1
and then navigates to any other control on the form he is able to edit the
form. In other words the form has now reset itself to allow edits in any and
all fields.

There are 4 control properties named cboLookup1, cboLookup2, cboLookup3, and
cboLookup4. If the user clicks or enters any one of these fields and then
exits to another field the form then allows edits.

There is code associated with these fields.

Here is the code that is in the LostFocus event on the combo box control
cboLookUp1.
Code:
Private Sub cboLookUp1_LostFocus()

Dim varExtCost As Variant
Dim varItem As Variant
Dim varCost As Variant

varItem = DLookup("descript", "tblItems", "[ItemNo]=cbolookup1")
If (Not IsNull(cboLookUp1)) Then Me![txtItem1] = varItem
varCost = DLookup("cost", "tblItems", "[ItemNo]=cbolookup1")
If (Not IsNull(cboLookUp1)) Then Me![txtCost1] = varCost


varExtCost = Nz(txtQty1, 0) * Nz(txtCost1, 0)
If (Not IsNull(txtQty1)) Then Me![txtExt1] = varExtCost

End Sub

The other 3 controls have the same code.

I know it has something to do with this code because I’ve removed the code
and the form will stay read only if this code does not fire. Yes, I’ve tried
putting AllowEdits = False statements in the LostFocus events and that
doesn’t help.

If anyone can offer any help it would be greatly appreciated.

Thanks for your time.
 
R

Rick Brandt

thesizz said:
I'm having a problem getting the AllowEdits property to work.

Here is the issue. I have a form - frmOrders . The forms Form_Current
event has the following line of code:

AllowEdits = False

This works fine and when the user tries to edit a field on the form
he is unable to. However, if the user clicks in or enters the control
cboLookup1 and then navigates to any other control on the form he is
able to edit the form. In other words the form has now reset itself
to allow edits in any and all fields.

There are 4 control properties named cboLookup1, cboLookup2,
cboLookup3, and cboLookup4. If the user clicks or enters any one of
these fields and then exits to another field the form then allows
edits.

There is code associated with these fields.

Here is the code that is in the LostFocus event on the combo box
control cboLookUp1.
Code:
Private Sub cboLookUp1_LostFocus()

Dim varExtCost As Variant
Dim varItem As Variant
Dim varCost As Variant

varItem = DLookup("descript", "tblItems", "[ItemNo]=cbolookup1")
If (Not IsNull(cboLookUp1)) Then Me![txtItem1] = varItem
varCost = DLookup("cost", "tblItems", "[ItemNo]=cbolookup1")
If (Not IsNull(cboLookUp1)) Then Me![txtCost1] = varCost


varExtCost = Nz(txtQty1, 0) * Nz(txtCost1, 0)
If (Not IsNull(txtQty1)) Then Me![txtExt1] = varExtCost

End Sub

The other 3 controls have the same code.

I know it has something to do with this code because I've removed the
code and the form will stay read only if this code does not fire.
Yes, I've tried putting AllowEdits = False statements in the
LostFocus events and that doesn't help.

If anyone can offer any help it would be greatly appreciated.

Thanks for your time.

If you set the value of a control on the form programmatically then the
AllowEdits is cancelled. After all you just made an edit. You could...

Modify the form so that those controls cannot get focus (endabled = false)

Modify the code so that when AllowEdits is False the values are not updated.

Modify the code so that AllowEdits is rest to False after setting the values.
 
J

Jeanette Cunningham

Hi thesizz,

The usual way that this sort of thing is set up is:

On the form's property sheet, on the Data tab,
set AllowEdits to No
This makes the form read only, but makes it impossible to do something with
the combo boxes.

To make the combo boxes work:
when the user enters the combo box, set the form's AllowEdits to True
after the user has made their selection and left the combo box,
set the form's AllowEdits to False

Jeanette Cunningham
 

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