How to lock information

  • Thread starter Thread starter HekaEnt
  • Start date Start date
H

HekaEnt

I created a database for my company which holds and submits a "Change to
Master(CTM)" document, any time a document or procedure in the company needs
to be changed they must fill out a CTM. We were routing a paper document
around the company and getting it signed off by the required managers, but
now we are going to a paperless system and setting it up in a database. As of
right now any user can input a CTM and also change exisiting requests in the
database. I want users to be able to only add the new information to the
database through the use of my forms and once they hit save that information
is turned into a read only on my form and locked from editing.
 
HekaEnt,
Use the AfterUpdate event of your CTM field...
If Not IsNull(CTM) Then
Me.CTN.Locked = True
End If
Place that same code in the OnCurrent event of your form. As users browse to a record,
if there is already a value in CTM, the field is locked.

Logically, I don't see the need to add an ElseIf IsNull Then... to that IF, since
users will only be given one shot before the field is locked.
--
hth
Al Campagna
Candia Computer Consulting
Microsoft Access MVP - Candia, NH USA
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
This makes sense on what it should do but i dont know exactly how to get it
to work, i should have stated that i am still a fairly beginner when it comes
to access. I can attach a link to the file in question if that would give
more people a better understanding on where i stand and how to help.

Al said:
HekaEnt,
Use the AfterUpdate event of your CTM field...
If Not IsNull(CTM) Then
Me.CTN.Locked = True
End If
Place that same code in the OnCurrent event of your form. As users browse to a record,
if there is already a value in CTM, the field is locked.

Logically, I don't see the need to add an ElseIf IsNull Then... to that IF, since
users will only be given one shot before the field is locked.
I created a database for my company which holds and submits a "Change to
Master(CTM)" document, any time a document or procedure in the company needs
[quoted text clipped - 5 lines]
database through the use of my forms and once they hit save that information
is turned into a read only on my form and locked from editing.
 
Ok, I think figured out where to put this information, (the properties in the
VBA editor for the CTM - Setup) and it is giving me this error
(afterUpdateError.bmp) and here is the exact code i am using

If Not IsNull(CTM - Setup) Then Me.CTM - Setup.Locked = True End If


The Form I want it to lock is named "CTM - Setup"

attached are two images showing where exactly I am entering in the
information

www.hekaent.com/Customers/P/PolyCast/images/afterUpdate.bmp
www.hekaent.com/Customers/P/PolyCast/images/onCurrent.bmp
www.hekaent.com/Customers/P/PolyCast/images/afterUpdateError.bmp
 
HekaEnt via AccessMonster.com said:
Ok, I think figured out where to put this information, (the properties in the
VBA editor for the CTM - Setup) and it is giving me this error
(afterUpdateError.bmp) and here is the exact code i am using

If Not IsNull(CTM - Setup) Then Me.CTM - Setup.Locked = True End If


The Form I want it to lock is named "CTM - Setup"

attached are two images showing where exactly I am entering in the
information

www.hekaent.com/Customers/P/PolyCast/images/afterUpdate.bmp
www.hekaent.com/Customers/P/PolyCast/images/onCurrent.bmp
www.hekaent.com/Customers/P/PolyCast/images/afterUpdateError.bmp
 
HekaEnt,
Please don't delete previous threads when responding. Just chain them all together so
I can see what you've said in past posts, and also see my own responses.

Since you've used spaces in your field names, they must always be bracketed, and you
haven't included an Else statement to enable the control if IsNull(CTM - Setup)

Your pics show your using Visiual Basic?
I'll write it in Access VB... you'll have to translate to VB...

If Not IsNull([CTM - Setup] Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If

That code goes in the AfterUpdatre event of [CTM - Setup] and the form's OnCurrent
event. It appears as though you're in the right place.. but with some faulty code. Use
my code, and try again.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
I didnt realize I deleted something, sorry about that. and I am using Access
VB for access 2000, I did try the new code and it is giving me the same error,
I then looked at your code and see that there is a "(" in front of the [CTM -
Setup] and I was curious as to if there should be another one to close out
the statement somewhere else in the code. I am also wondering if when you say
"That code goes in the AfterUpdatre event of [CTM - Setup] and the form's
OnCurrent
event." that you mean the table for the AfterUpdate or do you mean the form
for both the AfterUpdate and OnCurrent.

Al said:
HekaEnt,
Please don't delete previous threads when responding. Just chain them all together so
I can see what you've said in past posts, and also see my own responses.

Since you've used spaces in your field names, they must always be bracketed, and you
haven't included an Else statement to enable the control if IsNull(CTM - Setup)

Your pics show your using Visiual Basic?
I'll write it in Access VB... you'll have to translate to VB...

If Not IsNull([CTM - Setup] Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If

That code goes in the AfterUpdatre event of [CTM - Setup] and the form's OnCurrent
event. It appears as though you're in the right place.. but with some faulty code. Use
my code, and try again.
Ok, I think figured out where to put this information, (the properties in the
VBA editor for the CTM - Setup) and it is giving me this error
[quoted text clipped - 10 lines]
 
Yes The ")" should be there...
Whenever you get code via email, there is a chance of a syntax typo, so use your own
judgement and trouble shooting
if you get a synatx error.

If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If

*Always Copy and Paste your latest code so we can see if you've introduced some other
error beside my typo.

How that code is entered in Visual Basic is up to you. (as far as I can see, your not
programming in
Access 2000, but in Visual Basic with the Access 2000 objects connected to/imported into
it). There shouldn't be that much difference though
You might try... IsNull([CTM - Setup]) = False... instead of Not IsNull... but I'm not
sure about that...

You wrote...database through the use of my forms.

You have a form, and that form has an OnCurrent event. Place the code in that event.
You have a field [CTM - Setup], that control has an AfterUpdate event. Place that same
code in that event.
---
hth
Al Campagna
Candia Computer Consulting . Candia, NH
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love and you'll never work a day in your life."
HekaEnt via AccessMonster.com said:
I didnt realize I deleted something, sorry about that. and I am using Access
VB for access 2000, I did try the new code and it is giving me the same error,
I then looked at your code and see that there is a "(" in front of the [CTM -
Setup] and I was curious as to if there should be another one to close out
the statement somewhere else in the code. I am also wondering if when you say
"That code goes in the AfterUpdatre event of [CTM - Setup] and the form's
OnCurrent
event." that you mean the table for the AfterUpdate or do you mean the form
for both the AfterUpdate and OnCurrent.

Al said:
HekaEnt,
Please don't delete previous threads when responding. Just chain them all together
so
I can see what you've said in past posts, and also see my own responses.

Since you've used spaces in your field names, they must always be bracketed, and you
haven't included an Else statement to enable the control if IsNull(CTM - Setup)

Your pics show your using Visiual Basic?
I'll write it in Access VB... you'll have to translate to VB...

If Not IsNull([CTM - Setup] Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If

That code goes in the AfterUpdatre event of [CTM - Setup] and the form's OnCurrent
event. It appears as though you're in the right place.. but with some faulty code. Use
my code, and try again.
Ok, I think figured out where to put this information, (the properties in the
VBA editor for the CTM - Setup) and it is giving me this error
[quoted text clipped - 10 lines]
 
here is the code i am using and i am still getting that error concerning the
macro previously posted on image.

--------------
If Not IsNull([CTM - Setup]) Then [CTM - Setup].Locked = True
Else [CTM - Setup].Locked = False End If
--------------

Al said:
Yes The ")" should be there...
Whenever you get code via email, there is a chance of a syntax typo, so use your own
judgement and trouble shooting
if you get a synatx error.

If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If

*Always Copy and Paste your latest code so we can see if you've introduced some other
error beside my typo.

How that code is entered in Visual Basic is up to you. (as far as I can see, your not
programming in
Access 2000, but in Visual Basic with the Access 2000 objects connected to/imported into
it). There shouldn't be that much difference though
You might try... IsNull([CTM - Setup]) = False... instead of Not IsNull... but I'm not
sure about that...

You wrote...database through the use of my forms.

You have a form, and that form has an OnCurrent event. Place the code in that event.
You have a field [CTM - Setup], that control has an AfterUpdate event. Place that same
code in that event.
---
hth
Al Campagna
Candia Computer Consulting . Candia, NH
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love and you'll never work a day in your life."
I didnt realize I deleted something, sorry about that. and I am using Access
VB for access 2000, I did try the new code and it is giving me the same error,
[quoted text clipped - 32 lines]
 
I think you haven't entered the code where it needs to be placed.
You don't enter the code into the "text box" beside the OnCuurent event, you open the
code "module" for the OnCurrent event, and put the code in there. But in Visiual Basic
I can't be sure...
Here's how it's done in Visiual Studio... should be the same, or very close...

*First, delete anything you have in the OnCurrent textbox...*
Now try Double clicking the OnCurrent text box on the right, or the OnCurrent name box
on the left.
Does a module open up?

Here's an example for causing a Beep on FormActivated...
I double click the text box to the right of the Activated event
This appears...

Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Activated

End Sub

Now I place my code between those lines...

Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Activated
Beep()
End Sub

Now when I run the form, I get a "Beep" sound

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."



HekaEnt via AccessMonster.com said:
here is the code i am using and i am still getting that error concerning the
macro previously posted on image.

--------------
If Not IsNull([CTM - Setup]) Then [CTM - Setup].Locked = True
Else [CTM - Setup].Locked = False End If
--------------

Al said:
Yes The ")" should be there...
Whenever you get code via email, there is a chance of a syntax typo, so use your own
judgement and trouble shooting
if you get a synatx error.

If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If

*Always Copy and Paste your latest code so we can see if you've introduced some other
error beside my typo.

How that code is entered in Visual Basic is up to you. (as far as I can see, your not
programming in
Access 2000, but in Visual Basic with the Access 2000 objects connected to/imported into
it). There shouldn't be that much difference though
You might try... IsNull([CTM - Setup]) = False... instead of Not IsNull... but I'm not
sure about that...

You wrote...
I want users to be able to only add the new information to the
database through the use of my forms.

You have a form, and that form has an OnCurrent event. Place the code in that event.
You have a field [CTM - Setup], that control has an AfterUpdate event. Place that same
code in that event.
---
hth
Al Campagna
Candia Computer Consulting . Candia, NH
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love and you'll never work a day in your life."
I didnt realize I deleted something, sorry about that. and I am using Access
VB for access 2000, I did try the new code and it is giving me the same error,
[quoted text clipped - 32 lines]
 
Ok, i finally got it in the correct location and one is working, and the
other is not. it if giving me this error (image attached. attached is a image
showing my code exactly in the application.

----------

Private Sub Form_AfterUpdate()
If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If
End Sub

Private Sub Form_Current()
If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If
End Sub

----------

www.hekaent.com/Customers/P/PolyCast/images/error2465.jpg
www.hekaent.com/Customers/P/PolyCast/images/scriptError.jpg



Al said:
I think you haven't entered the code where it needs to be placed.
You don't enter the code into the "text box" beside the OnCuurent event, you open the
code "module" for the OnCurrent event, and put the code in there. But in Visiual Basic
I can't be sure...
Here's how it's done in Visiual Studio... should be the same, or very close...

*First, delete anything you have in the OnCurrent textbox...*
Now try Double clicking the OnCurrent text box on the right, or the OnCurrent name box
on the left.
Does a module open up?

Here's an example for causing a Beep on FormActivated...
I double click the text box to the right of the Activated event
This appears...

Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Activated

End Sub

Now I place my code between those lines...

Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Activated
Beep()
End Sub

Now when I run the form, I get a "Beep" sound
here is the code i am using and i am still getting that error concerning the
macro previously posted on image.
[quoted text clipped - 45 lines]
 
Try this on the AfterUpdate event of [CTM - Setup] (*delete the code you have in the Form
AfterUpdate event*)
Private Sub CTM___Setup_AfterUpdate()
If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If
End Sub

As far as the error... you need to pay attention to what the error message says, compare
what code I suggested vs. what you typed in, and put in a modicum of effort to solve the
problem yourself. Did you try DEBUG button from the error message?
Can't find field "|" ???
Look at your code!
If Not IsNull([CTM - |Setup]) Then
You introduced a "|" vertical bar character into the field name...

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."


HekaEnt via AccessMonster.com said:
Ok, i finally got it in the correct location and one is working, and the
other is not. it if giving me this error (image attached. attached is a image
showing my code exactly in the application.

----------

Private Sub Form_AfterUpdate()
If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If
End Sub

Private Sub Form_Current()
If Not IsNull([CTM - Setup]) Then
[CTM - Setup].Locked = True
Else
[CTM - Setup].Locked = False
End If
End Sub

----------

www.hekaent.com/Customers/P/PolyCast/images/error2465.jpg
www.hekaent.com/Customers/P/PolyCast/images/scriptError.jpg



Al said:
I think you haven't entered the code where it needs to be placed.
You don't enter the code into the "text box" beside the OnCuurent event, you open the
code "module" for the OnCurrent event, and put the code in there. But in Visiual
Basic
I can't be sure...
Here's how it's done in Visiual Studio... should be the same, or very close...

*First, delete anything you have in the OnCurrent textbox...*
Now try Double clicking the OnCurrent text box on the right, or the OnCurrent name
box
on the left.
Does a module open up?

Here's an example for causing a Beep on FormActivated...
I double click the text box to the right of the Activated event
This appears...

Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Activated

End Sub

Now I place my code between those lines...

Private Sub Form1_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Activated
Beep()
End Sub

Now when I run the form, I get a "Beep" sound
here is the code i am using and i am still getting that error concerning the
macro previously posted on image.
[quoted text clipped - 45 lines]
 
I debugged and found that error, and i re-typed the entire thing and still
got it. It says i introduced a vertical bar but there is no vertival bar in
the script so i dont know what is going on. What looks to you like a vertical
bar is the cursor. what i posted as text was the EXACT text/script from my
file.

Al said:
Try this on the AfterUpdate event of [CTM - Setup] (*delete the code you have in the Form
AfterUpdate event*)
Private Sub CTM___Setup_AfterUpdate()
If Not IsNull([CTM - Setup]) Then
[quoted text clipped - 3 lines]
End If
End Sub

As far as the error... you need to pay attention to what the error message says, compare
what code I suggested vs. what you typed in, and put in a modicum of effort to solve the
problem yourself. Did you try DEBUG button from the error message?
Can't find field "|" ???
Look at your code!
If Not IsNull([CTM - |Setup]) Then
You introduced a "|" vertical bar character into the field name...
Ok, i finally got it in the correct location and one is working, and the
other is not. it if giving me this error (image attached. attached is a image
[quoted text clipped - 59 lines]
 
Sorry, but there's nothing else I can do. The code you have now, should work. It's a
very simple IF statement.
As a good general rule, object names should not contain spaces, or special characters.
Perhaps VB is having problems with the name CTM - SetUp. Try CTMSetup instead. Can't
hurt.
Otherwise, try posting this question in a Visual Basic newsgroup. Were you actually using
Access, I would have you send me the file... but in VB, there's nothing more I can offer.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."

HekaEnt via AccessMonster.com said:
I debugged and found that error, and i re-typed the entire thing and still
got it. It says i introduced a vertical bar but there is no vertival bar in
the script so i dont know what is going on. What looks to you like a vertical
bar is the cursor. what i posted as text was the EXACT text/script from my
file.

Al said:
Try this on the AfterUpdate event of [CTM - Setup] (*delete the code you have in the
Form
AfterUpdate event*)
Private Sub CTM___Setup_AfterUpdate()
If Not IsNull([CTM - Setup]) Then
[quoted text clipped - 3 lines]
End If
End Sub

As far as the error... you need to pay attention to what the error message says, compare
what code I suggested vs. what you typed in, and put in a modicum of effort to solve the
problem yourself. Did you try DEBUG button from the error message?
Can't find field "|" ???
Look at your code!
If Not IsNull([CTM - |Setup]) Then
You introduced a "|" vertical bar character into the field name...
Ok, i finally got it in the correct location and one is working, and the
other is not. it if giving me this error (image attached. attached is a image
[quoted text clipped - 59 lines]
 
Hi HekaEnt,
HekaEnt wrote:
If Not IsNull(CTM - Setup) Then Me.CTM - Setup.Locked = True End If
The Form I want it to lock is named "CTM - Setup"

First, Access Forms does not have a property called "Locked". (i don't think
even exist in Access 2007)

If your wish to lock the form, use the "AllowEdits" property.

Something like,

Forms!Form1.AllowEdits = False

in your case maybe,....Forms![CTM - Setup].AllowEdits = False

or create function or sub in a new module.
 

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

Back
Top