Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't stop user from editing form

Status
Not open for further replies.

theSizz

Technical User
Apr 22, 2002
93
US
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.
 
I suggest that you search your code for AllowEdits. There may be another event that is firing. Youy could also try steping through the code.
 
I've reviewed all the code and there is no AllowEdits = True anywhere in the code.I think it has something to do with the code performing a lookup and then placing a value in another control.
What I don't understand is that when I enter the AllowEdits = False line of code in the LostFocus event it doesn't return to the form to read only.
 
Ok, that is odd. I find that saving the record fixes the problem. Just add:

Me.Dirty=False

To the end of the Sub.
 
That works but the problem with that is that once the user starts a new record and after the lostfocus event fires, he is unable to continue entering data in the remaining fields because the record has now been saved and is read only because the forms oncurrent event fires which sets the form to read only.
 
Check if it is a new record and don't save.

If Not Me.NewRecord Then
 
Thanks for the help remou that solves the problem
I really appreciate your time.
Thanks again.

For those of you following the issue this is the extra code that is added to the LostFocus event:

If Not Me.NewRecord Then
Me.Dirty = False
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top