Blockin' Registers.

Aeon.Divine

< Random Learner. >
Local time
Yesterday, 22:11
Joined
Mar 25, 2008
Messages
55
I have a form with a subform within. My need is to avoid already finished registries from being modified later. But when i turn the property off, this prevents my subform to be edited not only in older registries but in new ones as well. How should i correct this ?
 
How do you determine a "finished" registry? If you have a field that is filled out and that makes it finished then in the form's On Current event you can use:

Code:
If Len(Me.YourFieldName & "")=0 Then
   Me.AllowEdits = True
   Me.AllowAdditions = True
   Me.AllowDeletions = True
Else
   Me.AllowEdits = False
   Me.AllowDeletions = False
   Me.AllowAdditions = True
End If
And then
 
That one should block registries if one of their registries is completed. Could i add a yes/no field to my table called "blocked" and use a command or something to change its value blocking or not the order im seeing ?

If Me.blocked = No Then
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True
Else
Me.AllowEdits = False
Me.AllowDeletions = False
Me.AllowAdditions = True
End If

Would this code be ok for that matter ?

I suppose my command code would be something like:

If me.blocked = no then
me.blocked = yes
blockbutton.title = "unblock"
else
Me.blocked = no
blockbutton.title = "block"
end if

Would it work ?
 
If you set up Blocked as a Boolean (Yes/No) field then you can use this in the bound checkbox's After Update event:

Code:
If Me.blocked = False then 
   Me.blocked = True
   blockbutton.title = "unblock"
   Me.AllowEdits = True
   Me.AllowAdditions = True
   Me.AllowDeletions = True

else

   Me.blocked = no
   blockbutton.title = "block"
   Me.AllowEdits = False
   Me.AllowDeletions = False
   Me.AllowAdditions = True

End If

And then you would put that code in the Form's On Current event as well:
 
I dont get it. I should set up that code both on after update event and on current event ?

Was the button code ok ?
 
I modified your button code slightly, but you do have some latitude for change.

Yes, the button code was fine and I didn't quite "get it" so here you go (and Yes, you need it in the checkbox After Update event AND the form's On Current event otherwise as you move from record to record it won't check to see if it should be locked or unlocked).

For the Button:
Code:
If Me.blocked = False then 
   Me.blocked = True
   blockbutton.title = "unblock"

else

   Me.blocked = no
   blockbutton.title = "block"

End If

For the Checkbox
Code:
If Me.blocked = False then 
   Me.blocked = True
   blockbutton.title = "unblock"
   Me.AllowEdits = True
   Me.AllowAdditions = True
   Me.AllowDeletions = True

else

   Me.blocked = no
   blockbutton.title = "block"
   Me.AllowEdits = False
   Me.AllowDeletions = False
   Me.AllowAdditions = True

End If

For the form's Current event
Code:
If Me.blocked = False then 
   Me.blocked = True
   blockbutton.title = "unblock"
   Me.AllowEdits = True
   Me.AllowAdditions = True
   Me.AllowDeletions = True

else

   Me.blocked = no
   blockbutton.title = "block"
   Me.AllowEdits = False
   Me.AllowDeletions = False
   Me.AllowAdditions = True

End If
 
It's all properly working! Except for a tiny little detail.

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

This commands applied to my form doesnt block my text boxes nor my comboboxes, i can keep editing them as i please... i dont know what could be causing these lines not to work, but they do work if i block them manually from the design mode. Any ideas ?

Thanks for everything!
 
Are those on subforms instead of the main form?
 
They are in the main form. But i have a subform too. Anyhow the subform blocks itself just fine if i lock them manualy from the design view. if the code should have something else to block the subform, please let me know.
 
Im working in access 07, is there any problem with that ? I mean, i cant give you a mdb file only a .accdb file. I cant save it as an old database cause it includes new features.
 
Here

Here it is. At least i think so. Sorry but it's in spanish.

Hang on, ill have to take away some info for it to fit.
 
It didn't work. Did you do a compact and repair first (Office Button > Manage Database > Compact and Repair) and then zip it with WinZip or something else like it?
 
I just cant resume my database enough to make it fit here. I'll make you an example. Here it Goes
 

Attachments

Last edited:
The file is eddited in the previous reply. I hope it's enough to foind the problem.
 
Okay, sorry it took so long but I was too busy at work to work on this. Replace your code with this:

Code:
Private Sub Comando10_Click()

If Comando10.Caption = "unblock" Then
Comando10.Caption = "block"
Me.AllowEdits = True
Me.AllowDeletions = True
Me.AllowAdditions = True


Else

If Me.Dirty Then Me.Dirty = False
Comando10.Caption = "unblock"
Me.AllowEdits = False
Me.AllowAdditions = True
Me.AllowDeletions = False
End If

End Sub

Private Sub Form_Current()

   Comando10.Caption = "unblock"
   Me.AllowEdits = False
   Me.AllowAdditions = True
   Me.AllowDeletions = False
End Sub
 
What's that me.dirty field ?

This program would block any executed register, i mean ( form current executes on every opened register ), what we were looking for was for it to keep a record on blocked and unblocked registers and only showed as blocked previously blocked registers. thats why we needed the block field, so that it would save the register state.

Although, the form does block itself now, what was preventing that from happening before ?
 
What's that me.dirty field ?

This program would block any executed register, i mean ( form current executes on every opened register ), what we were looking for was for it to keep a record on blocked and unblocked registers and only showed as blocked previously blocked registers. thats why we needed the block field, so that it would save the register state.

Me.Dirty is a state, not a field. If an edit, or change has been made then the form is considered "dirty" and therefore

If Me.Dirty Then Me.Dirty = False

actually saves the record, which is necessary before you can lock the field again.

But, as far as not locking everything, go ahead an play with the current stuff and see what you can do. The only think that confused me I guess is that you didn't have the "blocked" field on the form, which you would need.
 
But the program still blocks every registry when i open them, it does not discriminate if they have been previously blocked or not. I know how to play with the current stuff to fix it. but wont it show me the same mistake i had when i sent it to you ?

I've just tested my modification. This is the code:

Code:
Private Sub Comando10_Click()

    If Comando10.Caption = "unblock" Then
    Comando10.Caption = "block"
    Me.Block = False
    Me.AllowEdits = True
    Me.AllowDeletions = True
    Me.AllowAdditions = True

Else

    If Me.Dirty Then Me.Dirty = False
    Comando10.Caption = "unblock"
    Me.Block = True
    Me.AllowEdits = False
    Me.AllowAdditions = True
    Me.AllowDeletions = False

End If

End Sub





Private Sub Form_Current()

If Me.Block = True Then

    Comando10.Caption = "unblock"
    Me.AllowEdits = False
    Me.AllowAdditions = True
    Me.AllowDeletions = False

Else

    Comando10.Caption = "block"
    Me.AllowEdits = True
    Me.AllowAdditions = True
    Me.AllowDeletions = True
    
End If
End Sub

The current protocol locks my register nicely, but if i use the button, it unblocks just fine, and then doesnt blocks again the fields. Something in the button code doesnt work. but the lines that block the form are just the same.
Maybe the Me.allowedits just works if i write it in a automatic protocol.. ( could that be possible ? )

It's almost finished but i still cant correct this problem, please.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom