Toggle button.

Tiesto_X

Registered User.
Local time
Today, 06:52
Joined
Jul 25, 2010
Messages
18
Can anyone help me to make code for Toggle button into form.
When I press it, its prevent single record editing and when unpress it alows editing.

I was trying to find on some previous posts, but had no success.

Tnx.
 
You don't need a toggle button simply a check box. If it is ticked allow edits and when unticked disable edits.
 
Tnx for ur answer.

I tried this code OnClick:

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

Doesnt work.

Any help?
 
Play with this concept:
Code:
with Me.commandButton
    Me.AllowAdditions = (.Caption = "Unlock Records")
    Me.AllowDeletions = (.Caption = "Unlock Records")
    Me.AllowEdits = (.Caption = "Unlock Records")
    .Caption = iif(.caption = "Unlock Records", "Lock Records", "Unlock Records")
end with
This translates to:
Code:
if Me.commandButton.Caption = "Lock Records" Then
    Me.AllowAdditions = False
    Me.AllowDeletions = False
    Me.AllowEdits = False
    Me.commandButton.Caption = "Unlock Records"
else
    Me.AllowAdditions = True
    Me.AllowDeletions = True
    Me.AllowEdits = True
    Me.commandButton.Caption = "Lock Records"
end if
They are essentially the same.
 
Last edited:
Tnx for ur answer, but seems somehow it doesnt work.
What might be a problem?
 
Forgive me for taking this post to make my question that I believe is similar.

I am also searching for a solution like this because sometimes I start typing on previous record instead on a new one. I wish I enter a locked form and If I want to edit it I could unlock either pressing a button or a check box. The problem is that I have tried some codes but no success.
I need something like if I am not in a new record I had a warning saying this is not a new record and asks if I want to edit it or not. Sometimes I have to browse the previous records to copy and paste some info that´s why this mistake happens.
Tks for your attention
 
Tnx for ur answer, but seems somehow it doesnt work.
What might be a problem?
That was in relation to DCrake's suggestion of using a button. Put one of the blocks of code in the click event of a BUTTON. You would obviously need to change the name of the button AND the initial caption of your button must be Lock Records.
 
Forgive me for taking this post to make my question that I believe is similar.

I am also searching for a solution like this because sometimes I start typing on previous record instead on a new one. I wish I enter a locked form and If I want to edit it I could unlock either pressing a button or a check box. The problem is that I have tried some codes but no success.
I need something like if I am not in a new record I had a warning saying this is not a new record and asks if I want to edit it or not. Sometimes I have to browse the previous records to copy and paste some info that´s why this mistake happens.
Tks for your attention
What you want is Me.NewRecord and Me.AllowEdits. Use the same concept as above, check if it's a new record, if not set Me.AllowEdits to false. The code will go in the On Current event and the click event of your button.
 
That was in relation to DCrake's suggestion of using a button. Put one of the blocks of code in the click event of a BUTTON. You would obviously need to change the name of the button AND the initial caption of your button must be Lock Records.

I changed both, name of a button and initial caption to Lock Records, but its still doenst work.
Also, i tried some stuffs with Check Box and still nothing.

Damn, i really thought that this code should be easy. I hunt it everywhere, and still no success.
 
When you say it doesn't work what happens? Can records be editted?
 
Yes, then can be editted with no problem. All i see that button is pressed or unpressed on click.
 
I meant, post a copy of your db and I'll have a quick look.
 
Just had a look at your db and you hadn't changed the names of the command button or set the caption of the button to "Lock Records".

See attached.
 

Attachments

Weard coz i did. I see u changed code a bit, but its still the same. I still can type while Lock Record button is activated.
 
You have to:

1. Open the form
2. Click the button once so that the caption is "Unlock Records"
3. Then try to see if you can edit the record
 
I oppened form, clicked button, tried to type and i could. Then i closed and Enabled Security warning stuffs and than worked.
Than i closed all over again, and now its showing Unlock Records and i still can type.
 
If it's worked once and it stopped working then your database must be corrupt. Create a new database shell and import all your objects into that.
 

Users who are viewing this thread

Back
Top Bottom