Lock current reccord

tstolk

Registered User.
Local time
Today, 07:39
Joined
Nov 29, 2005
Messages
13
Hi all!
This is my first post here so my appologies if I do something wrong AND my terrible English!! :cool:

I have made a database in Access where I can store all kind of information about hardware (laptop type, s/n, hdd size, memory etc.). Now it sometimes happens that an engineer will loose (!!) his laptop or it wil be stolen...

I want to build an option to mark the current record (of that stolen laptop) as stolen. Just with a checkbox. When i select the checkbox "stolen", all fields in the form of the current record has to be greyed-out. But just only for that record.
Is this possible?

Thanks in advance!

Kindest regards,
Tim
 
Last edited:
You can change the enabled property for the controls in VBA.
 
Searching the forum is a great way to discover and learn the answers to your Access programming questions.

-1 = True/Yes
0 = False/No


Code:
If ChkClosed = -1 Then

     Me.AllowEdits = True

Else

     Me.AllowEdits = False

End If
These commands will allow you define what they can or can not do based on the True or False argument.

Me.AllowAdditions = True
Me.AllowDeletions = True
Me.AllowEdits = True

Check out the AllowAdditions Property in Access help for some more examples and options on how to control what your users can do. Use the forms OnOpen event when using these type of commands.

Search the forum for more examples on how to turn those properties on/off based on a users network name or workgroup name.
 
Thanks for the replies!

I read the forum and searched it but could not find an answer to my question. I knew the allow.edits thing but thats not where I'm looking for.

Let see if I can change the question:
How can I greyed-out all field in a form just by cheking a checkbox?

Thnx! :)
 
We understood the question. It seems you didn't understand the answer.

Do you have experience of using the form control events to execute VBA? An event (such as ticking the checkbox or opening the form) can have VBA attached to it. ghudson has given you some code snippets which would form the basis of the VBA you would need to grey out your form controls.
 
To add alittle more:-
ghudson code would go in the onCurent event of the form so that it runs evertime you change record and you would also want it in the afterupdate event of the checkbox so that it runs when you check the box
The only down side with this method is that it will stop all Edits to the record including the Stolen Checkbox!

Peter
 
neileg said:
Do you have experience of using the form control events to execute VBA?
Yes I have, not much, experience with VBA. And i do know the Me.AllowEdits etc. commands. But this will not gray-out all fields in the form. This will only prevent updating the record. My goal is to gray-out all fields with ticking the box. It doesn't matter if the checkbox will gray-out also.

I don't know the VBA command for enable/disable a field (or in my case all fields) in a form. It has to look like this I guess? (I know this example is stupid and not working but it's only to clarify my idea)

If CheckBox thicked = -1 Then

Gray-Out all fields in the form

Else

Do nothing

Thnx!!
 
Each control on your form has an "enabled" property. You can set this to true or false for each control through vba on the afterupdate event for the tick box as mentioned above.
 
Yes, stephen81 is correct. The enabled property set to no will grey the controls, allow edits set to no will lock the data.

You will will need to set the properties of each control in turn.

You will need to use the code in the form open event and the after update event of the check box otherwise the controls will reset when the record is revisited.
 
stephen81 said:
Each control on your form has an "enabled" property. You can set this to true or false for each control through vba on the afterupdate event for the tick box as mentioned above.

Ok, that's clear! ;)
Only that's my question, what's the VBA code for "enabe = false" for all the controls in the form... :confused:

Thnx again! ;)
 
Ok, I found somthing which work great:

Code:
Private Sub Form_Current()

If checkbox = True Then
Me.textfield.Enabled = False

Else
Me.textfield.Enabled = True

End If
End Sub

Private Sub checkbox_AfterUpdate()

If checkbox = True Then
Me.textfield.Enabled = False

Else
Me.textfield.Enabled = True

End If
End Sub
Only this is just for 1 control named textfield but I want to have this for all controls at once in the form... Any ideas?

Thnx again and again and again! ;)
 
Last edited:
Just repeat the Me.textfield.Enabled= for each control you want greyed out.
 
You don't need to duplicate the code in the AfterUpdate of your checkbox, just replace the code with Form_Current or Call Form_Current
 
neileg said:
Just repeat the Me.textfield.Enabled= for each control you want greyed out.
That's the problem. There are a lot of controls in my form so that will be a hell of a job! And if something changes in the form (i.e. delete/add a control) you have to remember to change that list also! :(

So is there a code for all controls? Something like:

Code:
If checkbox = True Then
Me.[B]AllControls[/B].Enabled = False

Thnx in advance!
 
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "A" Then
If IsNull(Me.pd) Then
End If
If Me.pd = True Then
ctl.Locked = True
ctl.Enabled = False
Else
ctl.Enabled = True
ctl.Locked = False
End If
End If
 

Users who are viewing this thread

Back
Top Bottom