473,408 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to Enable/Disable fields based on Date

greeni91
Hi There,

I am making a database that is for a Maintenance Schedule. I am having a problem when it comes to locking the fields I don't need to see at this time.

I have a main date at the top of my form (txtDate) that displays today's date using the function =Date()

Next I have a date for the next Maintenance scheduled on a machine (txtNextDate).

What I am trying to do is lock the fields I don't need when txtDate is greater than txtNextDate.

I have tried some code in various different formats but they don't seem to be making one bit of difference to my form...

Can anyone help me before I lose all my hair please!!!

/Sandy
Aug 12 '10 #1

✓ answered by NeoPa

You might have some problems with that Chris.

I would expect (but only Sandy can say for sure) the property to use would be .Locked rather than .Visible. Two TextBoxes being compared would typically work on a string basis. This can give misleading results when working with dates (whose formats are unpredictable). Also, working with boolean values doesn't necessitate branching the code. If the variable is boolean and the calculation is boolean, then it makes most sense simply to assign the calculation to the variable.

Something like :
Expand|Select|Wrap|Line Numbers
  1. Me.Control1.Locked = (CDate(Me.txtNextDate) < Date())
  2. Me.Control2.Locked = (CDate(Me.txtNextDate) < Date())
Of course, this is in it's simplest form. If there are many controls a For ... Each would often make sense. Otherwise assigning the calculation to a boolean variable assures the calculation is not run over and over too many times.

7 2045
NeoPa
32,556 Expert Mod 16PB
You can run some code on the Open or Load events of the form. The control properties you may want to play with are :
.Visible
.Locked
.Enabled

Good luck Sandy :)
Aug 12 '10 #2
munkee
374 256MB
I think something simple like this would work in the form on open event

Expand|Select|Wrap|Line Numbers
  1. If (me.txtDate) > (me.txtNextDate) then
  2.  
  3. me.control1.visible = false
  4. me.control2.visible = false
  5.  
  6. Else
  7.  
  8. me.control1.visible = true
  9. me.control2.visible = true
  10.  
  11. End if
Aug 12 '10 #3
NeoPa
32,556 Expert Mod 16PB
You might have some problems with that Chris.

I would expect (but only Sandy can say for sure) the property to use would be .Locked rather than .Visible. Two TextBoxes being compared would typically work on a string basis. This can give misleading results when working with dates (whose formats are unpredictable). Also, working with boolean values doesn't necessitate branching the code. If the variable is boolean and the calculation is boolean, then it makes most sense simply to assign the calculation to the variable.

Something like :
Expand|Select|Wrap|Line Numbers
  1. Me.Control1.Locked = (CDate(Me.txtNextDate) < Date())
  2. Me.Control2.Locked = (CDate(Me.txtNextDate) < Date())
Of course, this is in it's simplest form. If there are many controls a For ... Each would often make sense. Otherwise assigning the calculation to a boolean variable assures the calculation is not run over and over too many times.
Aug 12 '10 #4
Thanks for the help guys,

I have tried both methods but neither of them give me the results I am looking for. I have put the code in the OnLoad() property as there is one record per machine, so when that record loads it will lock all appropriate checks for me.

I have noticed in the past that you usually need the code in another property as well, say an AfterUpdate() property, I will play around with these a little bit to see if I get any results.

NeoPa is correct when he says there could be a lot of controls, approx. 5, but I have never used a For...Each statement before. If it could be done with case statements as well I might have a chance of being able to get the code sorted.

Thanks for the help,

/Sandy
Aug 12 '10 #5
NeoPa
32,556 Expert Mod 16PB
Greeni91: I have tried both methods but neither of them give me the results I am looking for. I have put the code in the OnLoad() property as there is one record per machine, so when that record loads it will lock all appropriate checks for me.
Have you tried it in the OnOpen event procedure Sandy? Some data is not available to the code in the OnLoad one. This may be an example of that.

If you only have five controls to worry about, then listing them would make perfect sense. No need for a loop for just five items.

If you can let us know the names of the five and which property you would like to use (They all have different effects, but would all stop the controls' values from being changed), then we could show you how best to code it up.
Aug 12 '10 #6
Sorry Guys,

I screwed up when putting in the OnLoad() event, when I typed out the private sub I wrote it as _OnLoad(). Now that the event has the right name the code works perfect... I am following it as NeoPa suggested in his last post.

Thanks a lot guys... I still have some hair left, haha

/Sandy
Aug 12 '10 #7
NeoPa
32,556 Expert Mod 16PB
Is that all solved now then Sandy, or do you need any further help setting the .Locked properties for the five controls?

Actually, I would code it slightly differently for five of them :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Dim blnLock As Boolean
  3.  
  4.     With Me
  5.         blnLock = (CDate(.txtNextDate) < Date())
  6.         .Control1.Locked = blnLock
  7.         .Control2.Locked = blnLock
  8.         .Control3.Locked = blnLock
  9.         .Control4.Locked = blnLock
  10.         .Control5.Locked = blnLock
  11.     End With
  12. End Sub
Aug 12 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bob Bedford | last post by:
I've this code: function checkdate(FormSubmit){ alert(document.getElementById('Mois').value); if(eval(document.getElementById('Mois'))>0 && eval(document.getElementById('Annee'))>0){...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
6
by: ML.Steve | last post by:
Hi, There are lots of posts on this subject but after a couple of hours of going though them I still can't get a number of fields to be disabled when a checkbox is ticked. Basically I have a...
1
by: solanki.chandrakant | last post by:
Hi All, i m working on Linux Fedora Core 4. i have to develop one program in that i have device id. Based on given device id i have to enable/disable particular device id. i have to work with...
1
by: scanreg | last post by:
My form needs to (1) direct to specified URLs based on a combination of form selections and (2) enable/disable form features based on selections within the form FORM Radio 1 - A - B - C ...
6
by: Brandon McCombs | last post by:
Hello, I have a form that contains a listview on the left side and a column of buttons on the right side. Only some of the buttons do I want enabled all the time. The other buttons should be...
1
by: vibee | last post by:
I have part of a form where there are 3 fields to type in 3 questions. I want it so that the first question has to be typed in order for the second question to be typed and so forth. So when the...
2
by: Naushad | last post by:
Hi all, I am using the countinous form. I want to Enable/Disable the some fields for perticular records as per the following condition when open the form. I have written this code in "On Current...
1
by: ggfota | last post by:
How make some rows of a Form fully locked for edit based on criteria? Let's take two fields Date (criteria), Qty (editable). I will list all rows where Date is between DateFROM and DateTO. Now...
3
by: sanndeb | last post by:
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.