Link to home
Start Free TrialLog in
Avatar of madeatmidnite
madeatmidnite

asked on

New record acts like it is locked in continuous form.

I use the following code to lock the record if the checkbox is checked. (In continuous form)

If not Me.NewRecord then
    Me.Dirty = False
    Me!Med.Locked = Me!SaveCheck
    Me!Sig.Locked = Me!SaveCheck
    Me![start date] = Me!SaveCheck
end if

This works great except ONLY if there is a the SaveCheck box is checked on the LAST entered record.  If that is the case, then it will not allow me to enter a new record.  If that checkbox (the Last one only) is not checked, I can enter in information into a new record.  If it is checked, then the new record acts as if it is locked.  

I'm stumped.  Any help appreciated.

Thanks,
Carrie
Avatar of Arji
Arji
Flag of United States of America image

You can test for the state of SaveCheck and then do what you need:

If not Me.NewRecord then
  if Me!SaveCheck then
    Me.Dirty = False
    Me!Med.Locked = Me!SaveCheck
    Me!Sig.Locked = Me!SaveCheck
    Me![start date] = Me!SaveCheck
  end if
end if
Avatar of madeatmidnite
madeatmidnite

ASKER



Thanks for sticking with me Arji :)

Still doesn't seem to want to work.  Now if any of the Checkboxes are checked, it won't let any of the fields or records change, regardless of whether or not their checkboxes are checked.

Here is my code modified to be a subform:  

---------------------------------------------------------------------------------------
Private Sub Form_Current()

If Not Forms![AllergyMeds]![MedsCurrentForm].Form.NewRecord Then
If Forms![AllergyMeds]![MedsCurrentForm].Form!SaveCheck Then

Forms![AllergyMeds]![MedsCurrentForm].Form!.Dirty = False

Forms![AllergyMeds]![MedsCurrentForm].Form!Med.Locked = Forms![AllergyMeds]![MedsCurrentForm].Form!SaveCheck
Forms![AllergyMeds]![MedsCurrentForm].Form!Sig.Locked = Forms![AllergyMeds]![MedsCurrentForm].Form!SaveCheck
Forms![AllergyMeds]![MedsCurrentForm].Form![start date].Locked = Forms![AllergyMeds]![MedsCurrentForm].Form!SaveCheck


End If
End If
End Sub
-------------------------------------------------------------------------------------------------

Any thoughts?
Thanks, Carrie
Ok, I have really tried to figure this out.  If I take off the
 if Me!SaveCheck then

it works ok, even with the last checkbox checked until I go back and try to change one of the saved fields.  It doesn't let me change it --which it shouldn't.  But after that, the entire field in all the records seems to be locked.  It's really strange and I don't understand it.  If I (or the users) would never accidently click in one of the saved fields, it would be ok, but I don't think that I can count on that :)

Thanks,
Carrie
Hi Carrie,

For clarity's sake I'm going to assume AllergyMeds is the main form and MedsCurrentForm is the subform. AND the code is in the On Current event of the main form AllergyMeds.  I'm correcting some typos too....and removing the Bangs---> !

Logicaly the code checks to see if it's a new record,
then it checks the state of a checkbox on the subform,
if the checkbox is checked(True) then it locks the fields on the subform

You will also need to unlock them when SaveCheck is False so an Else condition is appropriate:

---------------------------------------------------------------------------------------
Private Sub Form_Current()

If Not Me.[MedsCurrentForm].Form.NewRecord Then
        If Me.[MedsCurrentForm].Form.SaveCheck Then

             Me.[MedsCurrentForm].Form.Dirty = False  '<-------Not sure what you are trying to do here

             Me.[MedsCurrentForm].Form.Med.Locked = True
             Me.[MedsCurrentForm].Form.Sig.Locked = True
             Me.[MedsCurrentForm].Form.[start date].Locked = True
        Else
             Me.[MedsCurrentForm].Form.Dirty = True '<-------Not sure what you are trying to do here

             Me.[MedsCurrentForm].Form.Med.Locked = False
             Me.[MedsCurrentForm].Form.Sig.Locked = False
             Me.[MedsCurrentForm].Form.[start date].Locked = False

        End If
End If
End Sub
Thanks for writing back.  I didn't have it on the on current of the Main form but on the subform.  But it still doesn't seem to work.  Now it doesn't seem to want to lock anything.

I'm going to try and play with this some more and see if I can get it to work.

thanks,
carrie
Now when I play with it, if the first record is  checked, then all of the records have their fields locked.  If the first record is not checked, then all the fields are not locked.
c
ASKER CERTIFIED SOLUTION
Avatar of Arji
Arji
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial