A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Locking Fields



 
 
Thread Tools Display Modes
  #11  
Old April 23rd, 2006, 11:37 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Mya,
I use the same type of code for one of my forms and all I did was add a
command button to the form to create a new record. When you click the command
button to create a new record have this code in it:

DoCmd.GoToRecord , , acNewRec
Call LockBoundControls([Form], False)

Anytime I open my form I have it go to the last record. So when I click on
the new record button it creates a new record and unlocks all controls.

HTH
SS

"Mya48" wrote:

I did and it is still not working for me.

"Allen Browne" wrote:

Did you try the form's Current event?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mya48" wrote in message
...
Can anyone help? I've got everything else working except when I am
entering
records. I can enter one because the form opens up on a new record but
when
I click the next record button I can't start typing in a field without
having
to click on the edit button. I've used the code below. This is driving
me
crazy.




  #12  
Old May 1st, 2006, 10:34 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Hello

this thread is great. i have used this to allow me to create a form that
uses all of the features of your code and to allow a new record button to
turn off the locked feature.

how would i make changes that allow me to store the locked or unlocked state
per record and change it in the code accordingly. i have a field in my table
that stores the locked or unlocked state but currently doesnt do a thing
because this is all form and code based at the moment. what i want to do is
to make the state change to allow me to cause no editing to be allowed on a
per record basis, but to allow me to change the locked state so that i can
allow editing if necessary.

the problem is this, i added the code that secret squirel suggested to my
"add new record button" that i have on my form.

Call LockBoundControls([Form], False)

this turned off the lock, but leaves it off for all records after i use the
button. is there a way to turn it back on when i got to previous records? or
to records that have been entered?

i think i just thought of it. i should put the same code in my other buttons
but make it true...

if you have another suggestion or better idea let me know here, i will be
trying my solution. thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mya48" wrote in message
...
I have a form which I want to lock all the fields unless the Edit button is
clicked. I didn't want to use the onload event on the form because then it
will only apply when it loads the form. I used the following code for the
Forms AfterUpdate Event:

Private Sub Form_AfterUpdate()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = True
Next
End Sub

and the following for the Edit Button Click Event:

Private Sub Edit_Record_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
End Sub

The problem I'm having is that when I first open the form and add a new
record, then click the add new record button I can't just start typing, I
first have to click on the edit button and then start typing into the
fileds.
Is there a way to fix that? Also, if I click on the edit button and I
don't
edit the record then click the next button, it doesn't end the command
until
I change a record.

Thank you.





  #13  
Old May 1st, 2006, 11:44 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Dawn,
I would try adding this code to the On Current event of your form;

Call LockBoundControls([Form], True)

This way after you add a new record and then scroll to a previous record it
will lock the form up again.The "On Current" event code will fire every time
you move to another record.

As for having a way to toggle back and forth between locking and unlocking
for record updates I would just add a command button to your form that will
lock/unlock your record for editing. Use this code provided by Allen Browne's
tip.

Dim bLock As Boolean
bLock = IIf(Me.cmdLock.Caption = "&Lock", True, False)
Call LockBoundControls(Me, bLock)


"DawnTreader" wrote:

Hello

this thread is great. i have used this to allow me to create a form that
uses all of the features of your code and to allow a new record button to
turn off the locked feature.

how would i make changes that allow me to store the locked or unlocked state
per record and change it in the code accordingly. i have a field in my table
that stores the locked or unlocked state but currently doesnt do a thing
because this is all form and code based at the moment. what i want to do is
to make the state change to allow me to cause no editing to be allowed on a
per record basis, but to allow me to change the locked state so that i can
allow editing if necessary.

the problem is this, i added the code that secret squirel suggested to my
"add new record button" that i have on my form.

Call LockBoundControls([Form], False)

this turned off the lock, but leaves it off for all records after i use the
button. is there a way to turn it back on when i got to previous records? or
to records that have been entered?

i think i just thought of it. i should put the same code in my other buttons
but make it true...

if you have another suggestion or better idea let me know here, i will be
trying my solution. thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mya48" wrote in message
...
I have a form which I want to lock all the fields unless the Edit button is
clicked. I didn't want to use the onload event on the form because then it
will only apply when it loads the form. I used the following code for the
Forms AfterUpdate Event:

Private Sub Form_AfterUpdate()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = True
Next
End Sub

and the following for the Edit Button Click Event:

Private Sub Edit_Record_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
End Sub

The problem I'm having is that when I first open the form and add a new
record, then click the add new record button I can't just start typing, I
first have to click on the edit button and then start typing into the
fileds.
Is there a way to fix that? Also, if I click on the edit button and I
don't
edit the record then click the next button, it doesn't end the command
until
I change a record.

Thank you.





  #14  
Old May 2nd, 2006, 12:57 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Hello

ah, that might have been simpler than my solution. i went through each of my
buttons and made them do "Call LockBoundControls([Form], True)" and that
solved my problem. but yours would do it in one fell swoop instead of 5
different buttons i had to do it to. thanks!


"Secret Squirrel" wrote:

Dawn,
I would try adding this code to the On Current event of your form;

Call LockBoundControls([Form], True)

This way after you add a new record and then scroll to a previous record it
will lock the form up again.The "On Current" event code will fire every time
you move to another record.

As for having a way to toggle back and forth between locking and unlocking
for record updates I would just add a command button to your form that will
lock/unlock your record for editing. Use this code provided by Allen Browne's
tip.

Dim bLock As Boolean
bLock = IIf(Me.cmdLock.Caption = "&Lock", True, False)
Call LockBoundControls(Me, bLock)


"DawnTreader" wrote:

Hello

this thread is great. i have used this to allow me to create a form that
uses all of the features of your code and to allow a new record button to
turn off the locked feature.

how would i make changes that allow me to store the locked or unlocked state
per record and change it in the code accordingly. i have a field in my table
that stores the locked or unlocked state but currently doesnt do a thing
because this is all form and code based at the moment. what i want to do is
to make the state change to allow me to cause no editing to be allowed on a
per record basis, but to allow me to change the locked state so that i can
allow editing if necessary.

the problem is this, i added the code that secret squirel suggested to my
"add new record button" that i have on my form.

Call LockBoundControls([Form], False)

this turned off the lock, but leaves it off for all records after i use the
button. is there a way to turn it back on when i got to previous records? or
to records that have been entered?

i think i just thought of it. i should put the same code in my other buttons
but make it true...

if you have another suggestion or better idea let me know here, i will be
trying my solution. thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mya48" wrote in message
...
I have a form which I want to lock all the fields unless the Edit button is
clicked. I didn't want to use the onload event on the form because then it
will only apply when it loads the form. I used the following code for the
Forms AfterUpdate Event:

Private Sub Form_AfterUpdate()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = True
Next
End Sub

and the following for the Edit Button Click Event:

Private Sub Edit_Record_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
End Sub

The problem I'm having is that when I first open the form and add a new
record, then click the add new record button I can't just start typing, I
first have to click on the edit button and then start typing into the
fileds.
Is there a way to fix that? Also, if I click on the edit button and I
don't
edit the record then click the next button, it doesn't end the command
until
I change a record.

Thank you.





  #15  
Old May 2nd, 2006, 01:00 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Glad I could help you out!

"DawnTreader" wrote:

Hello

ah, that might have been simpler than my solution. i went through each of my
buttons and made them do "Call LockBoundControls([Form], True)" and that
solved my problem. but yours would do it in one fell swoop instead of 5
different buttons i had to do it to. thanks!


"Secret Squirrel" wrote:

Dawn,
I would try adding this code to the On Current event of your form;

Call LockBoundControls([Form], True)

This way after you add a new record and then scroll to a previous record it
will lock the form up again.The "On Current" event code will fire every time
you move to another record.

As for having a way to toggle back and forth between locking and unlocking
for record updates I would just add a command button to your form that will
lock/unlock your record for editing. Use this code provided by Allen Browne's
tip.

Dim bLock As Boolean
bLock = IIf(Me.cmdLock.Caption = "&Lock", True, False)
Call LockBoundControls(Me, bLock)


"DawnTreader" wrote:

Hello

this thread is great. i have used this to allow me to create a form that
uses all of the features of your code and to allow a new record button to
turn off the locked feature.

how would i make changes that allow me to store the locked or unlocked state
per record and change it in the code accordingly. i have a field in my table
that stores the locked or unlocked state but currently doesnt do a thing
because this is all form and code based at the moment. what i want to do is
to make the state change to allow me to cause no editing to be allowed on a
per record basis, but to allow me to change the locked state so that i can
allow editing if necessary.

the problem is this, i added the code that secret squirel suggested to my
"add new record button" that i have on my form.

Call LockBoundControls([Form], False)

this turned off the lock, but leaves it off for all records after i use the
button. is there a way to turn it back on when i got to previous records? or
to records that have been entered?

i think i just thought of it. i should put the same code in my other buttons
but make it true...

if you have another suggestion or better idea let me know here, i will be
trying my solution. thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mya48" wrote in message
...
I have a form which I want to lock all the fields unless the Edit button is
clicked. I didn't want to use the onload event on the form because then it
will only apply when it loads the form. I used the following code for the
Forms AfterUpdate Event:

Private Sub Form_AfterUpdate()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = True
Next
End Sub

and the following for the Edit Button Click Event:

Private Sub Edit_Record_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
End Sub

The problem I'm having is that when I first open the form and add a new
record, then click the add new record button I can't just start typing, I
first have to click on the edit button and then start typing into the
fileds.
Is there a way to fix that? Also, if I click on the edit button and I
don't
edit the record then click the next button, it doesn't end the command
until
I change a record.

Thank you.





  #16  
Old May 2nd, 2006, 10:26 PM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Hello

i have a question related to this discussion.

how can i get the code to change the word "Unlock" to a red color text?

i found the word in the code, should i just highlight it and format it red?

Thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mya48" wrote in message
...
I have a form which I want to lock all the fields unless the Edit button is
clicked. I didn't want to use the onload event on the form because then it
will only apply when it loads the form. I used the following code for the
Forms AfterUpdate Event:

Private Sub Form_AfterUpdate()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = True
Next
End Sub

and the following for the Edit Button Click Event:

Private Sub Edit_Record_Click()
Dim c As Control
On Error Resume Next
For Each c In Me.Controls
c.Locked = False
Next
End Sub

The problem I'm having is that when I first open the form and add a new
record, then click the add new record button I can't just start typing, I
first have to click on the edit button and then start typing into the
fileds.
Is there a way to fix that? Also, if I click on the edit button and I
don't
edit the record then click the next button, it doesn't end the command
until
I change a record.

Thank you.





  #17  
Old May 3rd, 2006, 04:56 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

This will be another line of code, to set the ForeColor property of the text
box to vbRed.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"DawnTreader" wrote in message
...

i have a question related to this discussion.

how can i get the code to change the word "Unlock" to a red color text?

i found the word in the code, should i just highlight it and format it
red?

Thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to
No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html



  #18  
Old May 3rd, 2006, 05:39 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

Hello

ok, but i only want the word "unlock" to be red. i like the lock staying
black. if i change the ForeColor to red wont that do it for both "states" of
the button?

"Allen Browne" wrote:

This will be another line of code, to set the ForeColor property of the text
box to vbRed.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"DawnTreader" wrote in message
...

i have a question related to this discussion.

how can i get the code to change the word "Unlock" to a red color text?

i found the word in the code, should i just highlight it and format it
red?

Thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to
No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html




  #19  
Old May 3rd, 2006, 05:44 AM posted to microsoft.public.access.forms
external usenet poster
 
Posts: n/a
Default Locking Fields

So you will need to use an If block or an IIf() expression.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"DawnTreader" wrote in message
...
Hello

ok, but i only want the word "unlock" to be red. i like the lock staying
black. if i change the ForeColor to red wont that do it for both "states"
of
the button?

"Allen Browne" wrote:

This will be another line of code, to set the ForeColor property of the
text
box to vbRed.

"DawnTreader" wrote in message
...

i have a question related to this discussion.

how can i get the code to change the word "Unlock" to a red color text?

i found the word in the code, should i just highlight it and format it
red?

Thanks!

"Allen Browne" wrote:

Could you get away with just setting the form's AllowEdits property to
No,
while leaving AddAdditions as Yes?

That may not be enough if you have unbound controls you want to edit,
subforms that need to be set too, or selected controls that should not
be
unlocked. For those cases, see:
Locking bound controls on a form and subforms.
at:
http://allenbrowne.com/ser-56.html



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating fields and links before printing ... Sharon M. General Discussion 6 May 7th, 2006 11:58 PM
enable a field if a given field is checked off- otherwise- don't w babs Using Forms 9 April 18th, 2006 03:36 PM
Invisible Multiple Fields in PageHeaders (Word 2003) Roberto Villa Real Mailmerge 4 September 24th, 2005 10:53 PM
Word XE fields should be toggled fields, not Hidden Text. Monty Page Layout 1 September 16th, 2005 09:54 PM
improving performance by indexing query criteria fields Paul James Running & Setting Up Queries 20 February 16th, 2005 07:55 PM


All times are GMT +1. The time now is 04:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.