lock record code

  • Thread starter Thread starter Steel via AccessMonster.com
  • Start date Start date
S

Steel via AccessMonster.com

Hi,

I am currently working on code to lock specific records in a form and came
across a post with the following code that appears to do what I need. This
may be a very simple question but what does bLock refer to in this code?
Also, I interpret the first part of the code as: For the current form when
Year = 2004 then lock all records but what exactly does the second part of
the code do?

Private Sub Form_Current()
Dim bLock As Boolean
If Me.[Year] = 2004 Then
bLock = True
End If
If Me.AllowEdits = bLock Then
Me.AllowEdits = not bLock
Me.AllowDeletions = not bLock
End If
End Sub

Thanks.

Steel
 
Actually, all the first part

If Me.[Year] = 2004 Then
bLock = True
End If

does is set a variable to True if the year is 2004: it doesn't lock the
records.

It's actually the second part that determines whether or not it's supposed
to lock the records (by checking whether bLock is True), and then setting
the form's AllowEdits and AllowDeletions properties to False. (In actual
fact, you might also want to add Me.AllowAdditions = not bLock, so that
users cannot add new records to the database)
 
Is the variable bLock created in the process and, if so, where would this
variable be stored?

Thanks for the reply.

Steel
Actually, all the first part

If Me.[Year] = 2004 Then
bLock = True
End If

does is set a variable to True if the year is 2004: it doesn't lock the
records.

It's actually the second part that determines whether or not it's supposed
to lock the records (by checking whether bLock is True), and then setting
the form's AllowEdits and AllowDeletions properties to False. (In actual
fact, you might also want to add Me.AllowAdditions = not bLock, so that
users cannot add new records to the database)
[quoted text clipped - 19 lines]
 
bLock is a local variable to the routine. It isn't stored anywhere (nor is
it accessible from code in any other part of the database)

In actual fact, it isn't critical to the routine. It could just as easily
have been written as:

Private Sub Form_Current()

If Me.[Year] = 2004 Then
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = False
Else
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AllowAdditions = True
End If

End Sub


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Steel via AccessMonster.com said:
Is the variable bLock created in the process and, if so, where would this
variable be stored?

Thanks for the reply.

Steel
Actually, all the first part

If Me.[Year] = 2004 Then
bLock = True
End If

does is set a variable to True if the year is 2004: it doesn't lock the
records.

It's actually the second part that determines whether or not it's supposed
to lock the records (by checking whether bLock is True), and then setting
the form's AllowEdits and AllowDeletions properties to False. (In actual
fact, you might also want to add Me.AllowAdditions = not bLock, so that
users cannot add new records to the database)
[quoted text clipped - 19 lines]
 

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

Similar Threads

Locking a record 2
lock records code 2
Locked out of fields in Access 2000 11
Lock 1
Locking a record via a form 2
Locking records 1
Locking a single record or row in access subform 3
format fields with a button 2

Back
Top