Lock form edit under criteria

George82

Registered User.
Local time
Today, 14:00
Joined
Dec 8, 2011
Messages
15
[FONT=&quot]I have a form with 5 text boxes. A, B, C, D and F.[/FONT]
[FONT=&quot]Text boxes A, B, C, D have numeric values.[/FONT]
[FONT=&quot]Text box F is date.[/FONT]
[FONT=&quot]I want when text boxes A to D have the value 0 and text box F is filled with the date to lock edit for this registration and the corresponding row on the table.[/FONT]
[FONT=&quot]I want it to be visible by the users, maybe the fields in a deferent color (e.g. : light grey) if possible, but not to be able to edit it.[/FONT]
[FONT=&quot]I guess it would be in the after update event of the form. [/FONT]
[FONT=&quot]Could someone guide me throw the VB code?[/FONT]
 
I am sorry I am lost after the I want to part.. Could you please rephrase what you want to do?
 
Last edited:
Based on my understanding, I would say..

Code:
If TextA.Value=0 And TextB.Value=0 And TextC.Value=0 And TextD.Value=0 And isDate(TextF.Value) Then
    TextA.Enabled=False  
    TextB.Enabled=False  
    TextC.Enabled=False  
    TextD.Enabled=False  
    TextF.Enabled=False
End If

Enabled property will make it not editable and also greyed out. Locked will make is not editable, but clear as normal fields. Hope this is what you are looking for.
 

[FONT=&quot]I am using a table linked on a form to register our products and for our clients.[/FONT]
[FONT=&quot]On the form the trextboxes a,b,c,d I am mentioning are the number of accessories that come with the product and textbox f is the returned date.[/FONT]

[FONT=&quot]I want when user enters the value zero ‘0’ in text boxes a,b,c,d and also fills in the date in textbox f then and only then not to be able to edit this specific entry. To be locked.[/FONT]
[FONT=&quot]I say then and only then because if one of the a,b,c,d textboxes have values different than ‘0’ or textbox F is not filled then to be able to edit.[/FONT]

[FONT=&quot]I wrote something like this on the code:[/FONT]

[FONT=&quot]Private Sub Form_AfterUpdate()[/FONT]
[FONT=&quot]If Me.A = "0" And Me.B = "0" And Me.C = "0" And Me.D= "0" And Me.F = True Then[/FONT]
[FONT=&quot]Me.AllowEdits = False[/FONT]
[FONT=&quot]Else[/FONT]
[FONT=&quot]Me.AllowEdits = True[/FONT]
[FONT=&quot]End If[/FONT]
[FONT=&quot]End Sub[/FONT]

[FONT=&quot]But as I am new to access programming and VB… [/FONT]
[FONT=&quot]it does not work and I am sure that a lot of parameters must be missing..[/FONT]
[FONT=&quot]I hope I made it a little clearer.. [/FONT]
 
Last edited:
Form_AfterUpdate is fired at the very last stage. i.e. This method will be called for when Exiting/Navigating the record. That is the reason even though you have made it AllowEdits=False it still does not matter. Try using the code in the AfterUpdate of the Returned date.
 
[FONT=&quot]Still does not work… [/FONT]
[FONT=&quot]It prompts debug error in line : If A.Value = 0 And B.Value = 0 And C.Value = 0 And D.Value = 0 And IsDate(returned.Value) Then [/FONT]
[FONT=&quot]Moreover I don’t want to use it in the AfterUpdate event of the Returned Date as it’s not the last parameter that will be filed to disable the entry.[/FONT]
[FONT=&quot]Returned date might have date but one of the other textboxes might not be 0.[/FONT]
[FONT=&quot]If the user also buts 0 in this textbox then to be disabled.[/FONT]
[FONT=&quot]Any suggestions? [/FONT]
 
If possible can you upload a sample DB.. removing any sensitive data?? Maybe we are on different pages??
 
I am not exactly sure what your requierment is, but if this is your scenario..

If the trofodotiko, keraia, ethernet, sim are 0 and if there is a Date in the returned field then it should be locked. Then best place to put is Form_Load, else enable it.. So that it does not remain locked for all other records..
 
Please see attached print screen...

Thanks in advance!
 

Attachments

  • STEPS.jpg
    STEPS.jpg
    87.2 KB · Views: 87
Try this..
Code:
Private Sub Form_Current()
If TextA.Value=0 And TextB.Value=0 And TextC.Value=0 And TextD.Value=0 And isDate(TextF.Value) Then
    TextA.Enabled=False  
    TextB.Enabled=False  
    TextC.Enabled=False  
    TextD.Enabled=False  
    TextF.Enabled=False
Else
    TextA.Enabled=True  
    TextB.Enabled=True  
    TextC.Enabled=True  
    TextD.Enabled=True  
    TextF.Enabled=True
End If
End Sub
 
Code:
Private Sub Form_AfterUpdate()
If Me.A = 0 And Me.B = 0 And Me.C = 0 And Me.D= 0 And Me.F = True Then
    Me.AllowEdits = False
Else
    Me.AllowEdits = True
End If
End Sub
I removed the quotes since numeric values are not enclosed in quotes. Otherwise, the syntax is correct.

The code needs to be executed from two places.
1. The AfterUpdate Event of the form
2. The Current Event of the form

The first takes care of changes made to the current record. The second takes care of viewing an existing record.

pr2-eugin - I suspect that you come to Access from a different programming environment based on the syntax you use. In Access VBA, the .value property is the default ans so is generally omitted in VBA and MUST be omitted when you reference form fields from a query. More importantly, if you use the Me. qualifier you will be able to take advangage of intellisense which will save you typing because it will complete your control names for you plus give a list of valid properties and methods.

The .enabled property of a control prevents you from clicking into it. It also changes the background to gray unless Locked is also set to true. Sometimes it is desirable to not allow someone to even click into a control but most of the time, I just use the lock property. That allows the user to copy the string and paste it elsewhere so I find it more user friendly.
 
Thanks Pat, as a matter of fact, I do.. I had jumping from various platforms now doing VBA. Even that is not permanent. Might jump over to Java (again) in few months. Since I am an individual learner with only basic qualifications, I had to use Trial and Error methods along with my researching skills to learn all this. Well this Forum is one special place where I learn. I now understand what you mean. Thanks. :)
 

Users who are viewing this thread

Back
Top Bottom