conditional lock

I

Ian

I have a form with several fields. Once it has been printed (a printed
yes/no box is updated to yes) I'd like the locked feature of the record to be
turned on. Is there a way to do that?

Thanks in advance. Ian.
 
A

Al Campagna

Ian,
Set the AllowEdits and AllowDeletes properties of the form to No.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
I

Ian

Can you help with code:
On GotFocus....
If ((Allowedits Or AllowDeletions) AND Me!Printed = -1) = True Then
Set.Allowedits = False
Set.Allowedits = False
Else
Field.SetFocus
End If
End Sub
 
A

Al Campagna

Ian,
Locking a record after a report has printed can be an "iffy" proposition, since Preview
and Print essentially trigger the same events. So, for instance, if you used the report
Close event to determine that the report has "printed"... Print Preview (without actually
"printing") will fire the same code.
So...logically there's not any real difference between putting the checkbox update in
the OpenReport event, or the Report Close event... either logic is a bit shaky.
Place this code in the Close event of the report... (use your own object names)
Private Sub Report_Close()
Forms!YourFormName!chkPrinted = True
Forms!YourFormName.Form.AllowEdits = False
Forms!YourFormName.Form.AllowDeletions = False
Forms!YourFormName.Form.Refresh
End sub

But, you will also need to determine the Lock status when browsing from record to record,
so place this code in the OnCurrent event of the Form...
Private Sub Form_Current()
If chkPrinted = True Then
Me.AllowEdits = No
Me.AllowDeletions = No
Else
Me.AllowEdits = Yes
Me.AllowDeletions = Yes
End If
End Sub

OR... in a shorter method
Private Sub Form_Current()
Me.AllowEdits = Not chkPrinted
Me.AllowDeletions = Not chkPrinted
End Sub

Note: You'll probably need some method to Override the Lock. Otherwise the Lock can only
be removed via the table.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
I

Ian

Thanks Al -- what I do is that after the report has run and on close I put a
pop-up that says ?Mark Services printed? -- then they hit yes or no and an
append query alters the printed checkbox for the records that were in the
query/report.

I'm also going to base the if statement on a query so that if the ID is not
in a seperate table it will lock them out also. So I think I'll just need to
amend the On Current () code to make it work. Thanks a lot for the code.
Ian.
 
A

Al Campagna

That's the ticket... just previewing or printing is not reliable enough to trigger the
Printed/Lock.
Your message box will do the trick...
Good luck,
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
N

Nicole

Dear Al,

I used your code for my application and it works great (others I tried were
very frustrating). However, I've figured out how to unlock the record on a
user level. Not great. This is not a huge issue as long as I can keep this
a secret, but I was hoping you could offer me some advice.

I have a pop up calender which is called up when the user uses a list box to
add a date. These fields do not lock with your code and when used unlock
every other field that was previously locked.

Thanks, Nicole
 
Top