473,408 Members | 2,839 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.

Forms: Disable field(s) based on inputted value of another field

3
Hi,

It has been ten years since I used access - and that was on a very basic level at school!!! I am thus way way out of my depth and would appreciate some help...

I am designing a database that records the ins and outs of a bicycle recycling scheme and am a little stuck on the data input form...

For each bicycle that needs to be recorded on the database, there are two possibilities: either it has been received or it has been tagged and is awaiting retrieval.
For any bike that has been received, its source and date of arrival must be recorded.

My question, is therefore this: given that on my form the "received" field is a checkbox, how do I make the availability of the "source" and "arrival date" fields dependent upon the value of the checkbox?

Can the same be done for the "tagged" field, given it is a checkbox?

Please remember I have no experience of coding in access...I am, however, extremely grateful for any assistance that may be given...
If anything is unclear please ask and I will try and clarify.

Many thanks, rab26
Oct 28 '15 #1

✓ answered by NeoPa

No. Further questions will be unlikely as I see it. That's because you've explained it well. A rare occurrence for a first-timer.

One confusion I do have though, is why do you think you need a field/control for Tagged when you already have one for Received - since the logic clearly determines one from the other. Unless I'm missing something that would be logical tautology - a failure to follow the guidelines of Normalisation theory (See Database Normalisation and Table Structures).

First let's just take a minute to clarify some terminology. Reports and Forms have Controls that manage the Fields of the record source. Controls needn't have associated fields, but what we're working with here are controls. FYI. Those without associated Fields are termed Unbound Controls.

Controls have various properties, or attributes, that you can use to help manage the form, as well as the controls - and via them the fields - on it.

One point to consider is that there are two points at which the value of a control can be different from the previous value :
  1. When the control is changed. EG. When clicked for a CheckBox.
  2. When a different (or first) record is loaded.

In each situation the other controls need to be set to match the current value. This can be done in VBA code. I'll show an example of that here in a general procedure then discuss later how and when this procedure may be called. In my example code I will name the controls in a way that's standard for their control types. IE. [chkReceived], [txtSource] & [txtDateReceived] :
Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowControls()
  2.     With Me
  3.         .txtSource.Visible = .chkReceived
  4.         .txtDateReceived.Visible = .chkReceived
  5.     End With
  6. End Sub
Notice that this procedure will both show and hide the extra controls depending on whether [chkReceived] is set or clear.

Now we know what we need to do, we need to ensure it's done at the appropriate points. We've already seen the .Visible property of two controls being used to show and/or hide the controls themselves. Now we're going to look at two more properties related to the control itself (chkReceived], and to the form.
  1. .AfterUpdate is a property that sets what happens when the control is updated. Setting this to the string value "[Event Procedure]" in the Properties pane for the control will ensure our VBA procedure is called. Click on the ellipsis (...) button to the right of the value for Access to create the procedure for you automatically.
  2. .OnCurrent (on the Form) does a similar job for whenever a record is changed. This includes when the first record is loaded.
Below is some example code for these two event procedures.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call ShowControls
  3. End Sub
  4.  
  5. Private Sub chkReceived_AfterUpdate()
  6.     Call ShowControls
  7. End Sub
Try this and see how you get on.

4 1026
NeoPa
32,556 Expert Mod 16PB
No. Further questions will be unlikely as I see it. That's because you've explained it well. A rare occurrence for a first-timer.

One confusion I do have though, is why do you think you need a field/control for Tagged when you already have one for Received - since the logic clearly determines one from the other. Unless I'm missing something that would be logical tautology - a failure to follow the guidelines of Normalisation theory (See Database Normalisation and Table Structures).

First let's just take a minute to clarify some terminology. Reports and Forms have Controls that manage the Fields of the record source. Controls needn't have associated fields, but what we're working with here are controls. FYI. Those without associated Fields are termed Unbound Controls.

Controls have various properties, or attributes, that you can use to help manage the form, as well as the controls - and via them the fields - on it.

One point to consider is that there are two points at which the value of a control can be different from the previous value :
  1. When the control is changed. EG. When clicked for a CheckBox.
  2. When a different (or first) record is loaded.

In each situation the other controls need to be set to match the current value. This can be done in VBA code. I'll show an example of that here in a general procedure then discuss later how and when this procedure may be called. In my example code I will name the controls in a way that's standard for their control types. IE. [chkReceived], [txtSource] & [txtDateReceived] :
Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowControls()
  2.     With Me
  3.         .txtSource.Visible = .chkReceived
  4.         .txtDateReceived.Visible = .chkReceived
  5.     End With
  6. End Sub
Notice that this procedure will both show and hide the extra controls depending on whether [chkReceived] is set or clear.

Now we know what we need to do, we need to ensure it's done at the appropriate points. We've already seen the .Visible property of two controls being used to show and/or hide the controls themselves. Now we're going to look at two more properties related to the control itself (chkReceived], and to the form.
  1. .AfterUpdate is a property that sets what happens when the control is updated. Setting this to the string value "[Event Procedure]" in the Properties pane for the control will ensure our VBA procedure is called. Click on the ellipsis (...) button to the right of the value for Access to create the procedure for you automatically.
  2. .OnCurrent (on the Form) does a similar job for whenever a record is changed. This includes when the first record is loaded.
Below is some example code for these two event procedures.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.     Call ShowControls
  3. End Sub
  4.  
  5. Private Sub chkReceived_AfterUpdate()
  6.     Call ShowControls
  7. End Sub
Try this and see how you get on.
Oct 28 '15 #2
zmbd
5,501 Expert Mod 4TB
Hopefully you have started out with normalizing your data-tables (Insights>Database Normalization and Table Structures)

Once you have that done, the rest should fall in to place fairly rapidly.

What concerns me here is that you have a checkbox related to your received date data somehow... why?

Here's kind of my thought,

Table to hold your locations - include one entry for "in transit"
Table to hold your bike inventory
Table to hold the events

So, the data entry would be something along this line

Event: Bike(ABC) arrives 2015-10-28@18H41GST at station 6
Event: Bike(ABC) In-Transit 2015-10-28@18H50GST
Event: Bike(ABC) arrives 2015-10-28@20H40GST at station 1

Entry in the event table
Expand|Select|Wrap|Line Numbers
  1. [PK ][DatetimeField   ][FK_BikeInvtry][FK_Location]
  2. [203][2015-10-28 18:41][6            ][25]
  3. (other events)
  4. [203][2015-10-28 18:50][6            ][1]
  5. (other events)
  6. [987][2015-10-28 20:40][6            ][15]
...

Need to check the status of a bike then one would query on [FK_BikeInvtry] = 6, sort order on the date [DatetimeField] descending, return TOP 1... you can filter the records down more by WHERE [DatetimeField]> today's date starting at 00h00

I know that's not directly answering your question; however, I hope it gives you some working ideas...
Oct 28 '15 #3
rab26
3
NeoPa: Thank you for your great response - and for sorting out terminology.
To answer your question:
"why do you think you need a field/control for Tagged when you already have one for Received - since the logic clearly determines one from the other"
The tagged bikes do eventually reach us...furthermore, bikes come from several different sources and those received from security may or may not have been tagged. The tagged checkbox thus needs to be made available should security be selected as the source.
Although I don't think this breaks the guidelines of normalisation theory (please correct me if I am wrong), it is convoluted and complicates matters...my logic may therefore be failing me. Indeed - I seem to be on a pathway heading for duplicate records as I have neglected the fact that tagged bikes will already be in the database by the time they are received...hmmm :-)
I will have a bash at the event procedures using your example code and let you know how I get on.
ZMBD: Thank you also for your response.
I think I have misused some terminology in my original question and thus mislead you...the "received" checkbox is, learning from what NeoPa has written, an unbound control: it is not actually associated with a field in a table: I am simply attempting to use it to determine which controls are visible and need to be completed when a record is produced.
That said, however, your post has given me food for thought. Thank you.
Oct 29 '15 #4
NeoPa
32,556 Expert Mod 16PB
Hi Rab.

At this point I would only point out the importance of getting your detailed understanding of the logic absolutely and completely understood before doing anything else. Anything you implement at this stage can be up for review and redoing if the basis it's created on is flawed or changes. Think of the understanding, then the design, as the lowest two tiers of a pyramid. Get those right and consistent and you have a solid base upon which to build the rest of the structure. Get them wrong and you're building on shifting sands.

Good luck :-)
Oct 29 '15 #5

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

Similar topics

6
by: jochen scheire | last post by:
Is there a way I can calculate a field in a form based on another field in the same form. When clicking submit, both values should be posted to the next page. I want to be able to type in a value...
3
by: RRT | last post by:
I have an existing table which describes Streets and sections of streets between intersections: Table 1: Streets by Intersections Street Area Ann St. Main to Jackson...
4
by: Bob Alston | last post by:
I have some dates which show in a continuous form, multiple rows at a time. I would like to color the background yellow, or the text yellow or some color other than black that would stand out,...
4
by: Haas C | last post by:
Hi all, I was wondering if any of you guys can help me out with this: I have two fields on a form: one field is Premium and the other is Brokerage. Whatever amount is in the Premium field is...
14
by: mjvm | last post by:
HI, I have had a search for the answer to this question, but I can't transfer what I am reading to my database. I don't know enough about the language required, but have been able to get my...
3
by: BobbyD1120 | last post by:
I have created a inventory tracking database and I want to show/hide certain fields based on the device category. The deviceCategory field is a lookup field to a table that lists all the different...
4
by: nedryerson | last post by:
Hi, I'm trying to get a certain field to appear only when a value from another combobox field is selected. Specifically, when "Sample Rejected" is selected in the field "PcrLabResults," I would...
7
greeni91
by: greeni91 | last post by:
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...
5
by: Redbeard | last post by:
I am trying to change the font colour of certain records in a Multiple Item Form based on what value is in a Combo-box. The code below works for a single record view form but not the multi. It will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.