[access] field visible on condition
Hello, I am new to this forum and I am seeking help from Access specialists. I am creating a furniture management database (tables, forms) and so far, no problem. In a form, I have two fields: a "Category" field and a "Seat Height" field. I want the "Seat Height" field to appear when the "Category" field contains the value "Seat". I wrote the following code in the After Update property of the "Category" field:
If [Category] = "Seat" Then
[Seat Height].Visible = True
Else
[Seat Height].Visible = False
End If
This does not work because it applies to all records in the table and does not remain in memory on the specific record.
How can I do this? Thank you for your valuable help
If [Category] = "Seat" Then
[Seat Height].Visible = True
Else
[Seat Height].Visible = False
End If
This does not work because it applies to all records in the table and does not remain in memory on the specific record.
How can I do this? Thank you for your valuable help
Configuration: Windows XP Access 2003
26 answers
-
Anonymous userHello,
you also need to put this code on the current() event of the form.
--
When Jimmy says what’d I say, I love you baby
It’s like saying, the whole province singing in English -
babdoulHello,
I am making a program in Access 2003 for managing a car fleet.
I would like to know how to integrate the depreciation schedule for the vehicles, which is titled as follows:
Acquisition date: DA
Value date: DV
Acquisition cost: CA
DV1 = DA + 365 days
CA1 = 75%*CA
DV2 = DV1 + 365 days
CA2 = 50% *CA
DV3 = DV2 + 365 days
CA3 = 25% * CA
DV4 = DV3 + 365 days
CA4 = 0% * CA
Your help would be very valuable to me. -
KlyslaneHello everyone,
I have a problem similar to yours but the proposed solutions aren’t working...
I’m editing invoices using Access 2010. The report retrieves the necessary information from the forms filled out previously.
I have 3 fields that should only display if they are different from 0 and I’m unable to do that.
I right-click, create an event, code generator. I type this:
Private Sub Quantité_achat_pour_vente_Enter()
If Quantité_achat_pour_vente <> 0 Then
Quantité_achat_pour_vente.Visible = True
Else
Quantité_achat_pour_vente.Visible = False
End If
End Sub
And so when I open my report it gives me an error message because in the properties of my field I have visible = YES. My only other choice is NO and I am forced to leave the field filled.
Any ideas?
Thanks thanks! -
FabriceHello everyone,
I also have an issue with a continuous form where I have an image that I want to display (or not) depending on the value of field S1. (if S1<0, display the image)
I entered the following code (access 2002)
Private Sub Form_Current()
If [S1] < 0 Then
[alert].Visible = True
Else
[alert].Visible = False
End If
End Sub
The problem is that the display is the same for all records...If I select a negative value in one of the records, the image is displayed properly but for all records (even those where field S1 is >0). I applied your different suggestions, but it still doesn’t work!
Thank you in advance to those who will take the time to help me, and well done to everyone for the quality of your responses
Best regards-
Anonymous userHi Fabrice,
of course, it doesn't work for continuous mode forms.
If you have the courage: https://cafeine.developpez.com/access/tutoriel/pseudocontinu/
--
When Jimmy says what’d I say, I love you baby
It's like saying, the whole province singing in English
-
-
Fab
If checkbox_name = True Then 'if the checkbox is checked
Me!field_to_hide.Visible = True 'show the text box1
Else
Me!field_to_hide.Visible = False
End If -
FabHi everyone,
Just to thank you, your many suggestions on this post helped me solve my problem without having to ask a question. Namely, displaying fields when a checkbox is checked.
It’s very simple after all:
1 - right-click on the checkbox - create event code
2 - enter this (with your field names of course)
If checkbox_name = True Then 'if the box is checked
Me!field_to_remove.Visible = True 'show text box1
Else
Me!Location.Visible = False
End If
3 - select Form from the choice list above on the left and "current" from the choice list on the right in VBA and copy exactly the same code
If checkbox_name = True Then 'if the box is checked
Me!field_to_remove.Visible = True 'show text box1
Else
Me!Location.Visible = False
End If
See you later
Fab-
SquatinaHello,
I wrote this code in VBA:
Code:
If checkbox_name = True Then 'if the checkbox is checked
Me!photo1.Visible = True 'show photo1
Else
Me!photo1.Visible = False
End If
So that photo1 appears in my form1 when the corresponding checkbox is checked.
But now I nested my form1 inside another form2.
And I would like the photo to show in form2 instead of form1.
What modification should I make to my code for the photo to be placed in form2, please?
I'm sure it's simple but I can't find it.
-
-
François35I’m coming back to this post again...
I have another issue, but of the same level...
Still in the same database.
In my quote form, when I enter a product, I want it to appear either in the "quote" state or in the "delivery note" state, or both...
So I created 2 checkboxes on my items: one for "appear on quote" and one for "appear on DN"
I right-clicked on the checkbox and selected "create event code" and I entered:
if [Ab2]=true then
me! États![P_Devis#Devis#]![AbsMontant].Visible = true
else
me![Ab2].visible=false
Legend: [Ab2] is my checkbox
[AbsMontant] is what should display or not, which is found in the report P-Devis#Devis#
I close it, and when I click on the checkbox for the item, it tells me:
Microsoft Office Access cannot find the macro if [Ab2]=true then
me! États![P_Devis#Devis#]![AbsMontant].
The macro (or its macro group) does not exist, or the macro is new but has not been saved.
Note that when you enter the syntax groupnamemacro.macroname in an argument, you must specify the name under which the macro group of the macro was last saved.
Then it still checks the box but does not change the quote state...
Anyway, I’m a bit lost... thanks to those who can help clarify my problem. -
Laura HoltHello,
My problem has led me to this discussion. I see that some of you are skilled in Access (lucky you) and I need your valuable help.
I have a database called "contract" that includes several tables (info, contacts, billing, scheduling, date, etc.). I have created forms and subforms for data entry to make it easier for my users.
Furthermore, some contracts have been terminated and I do not want to delete the record but only hide it using a checkbox, for example, active or inactive. While still being able to find them by clicking a button "show inactive contracts."
I know it is possible to hide "inactive" records using a query. But my records are established directly from several tables.
I have not yet set up any macros in my database. I don’t master macros in Access (but I can manage in Excel)
Is this possible?
Thank you.
LH
PS: do you know a site explaining SQL language formulas? Thank you.-
Anonymous userHello,
you have a choice: either by SQL or by code.
By code, I'll let you look at the different interventions in this message; you'll probably understand.
For SQL, you need to change the source of your form that displays the “records”; first, you need to create a “visible” field in the contract information table, of type “yes/no”. Add a control of the same type in the form.
Then, in the source of your form (in design mode, properties), add this field and set the condition to “false”.
This way, your form displays the records that have this checkbox unchecked.
I hope you understand; otherwise, don't hesitate to ask.
Catch you later
--
When Jimmy says what’d I say, I love you baby
It’s like saying, the whole province singing in English -
Laura Holt@Anonymous userHello HDU,
(ACCESS 2007)
Thank you for your response. I think I understand the method, but I can't find the "condition" line in the properties to set it to "false".
Here's what I've done:
I started with my already well-filled database
So I created (at the time) a field "Effectué" of type "yes/no",
I went to my form, removed this field "effectué", then I reinserted it (just in case) through "add existing fields"
Then I right-click on the checkbox in the form and access the properties. I have several tabs: Format, Data, Event, Other & All. Where should I put "False"?
Thank you for your response.
LH -
Anonymous user@Laura HoltHello,
You need to put the condition in the form's source, not in the checkbox properties...
Open your form in design mode (so for editing), and go to View, properties.
- Either your form is based on a query and you have access to this query in the 'source' line of the properties (data tab, or if not, all) and you modify the source query of this form by adding the field and putting the condition "false" on the 'criteria' line.
- Or your form is based on a table, and you don't want to create a query, then you just need to add, on the 'filter' line "completed is false" (without the quotes).
Is that clear?
See you later
--
When Jimmy says what’d I say, I love you baby
It's like saying, the whole province singing in English -
lauraholt@Anonymous userThank you for your response.
Finally, I found the "filter" line in the properties of the form, then the "data" tab where I wrote Completed=False.
It works, but if I want to enter a record (with the filter in place), I can't do anything, all the cells are locked. Why is that and what can I do?
Thank you
--
LH -
Anonymous user@lauraholtRe,
A filter shouldn't lock your input. Can you provide the source of your form? Can you try removing just the filter and let me know if it works?
See you!
--
When Jimmy says what’d I say, I love you baby
It's like saying, the whole province sings in English
-
-
tili67Hello,
I have a similar problem but in Word.
I created a form and I would like the checkboxes to be interactive when someone fills it out.
Let me explain: in the question about the product material, there are options for Steel or Stainless Steel, and I want the person filling it out to be able to check only one box (either one or the other, but not both).
Thank you. -
MiiHello,
I also have a problem trying to make a field visible conditionally.
The field remains visible regardless of the condition.
Here is my code, hoping someone can help me.
Private Sub Form_Current()
If EMPLOI = "Unemployed" Then
nivrequis.Visible = False
Else
nivrequis.Visible = True
End If
End Sub
Private Sub nivrequis_BeforeUpdate(Cancel As Integer)
If EMPLOI = "Unemployed" Then
nivrequis.Visible = False
Else
nivrequis.Visible = True
End If
End Sub-
domik[access] field visible on condition
Hello,
try this:
Private Sub Form_Current()
If [EMPLOYMENT]= "Unemployed" Then
me.nivrequis.Visible = False
Else
me.nivrequis.Visible = True
End If
End Sub
Private Sub nivrequis_BeforeUpdate(Cancel As Integer)
If [EMPLOYMENT] = "Unemployed" Then
me.nivrequis.Visible = False
Else
me.nivrequis.Visible = True
End If
End Sub -
Mii@domikThank you for your reply, domik! ;-)
-
-
Anonymous userHello,
At first glance, if I stick exactly to what you're telling me, you have a quote table with product codes in it?
If that's the case, it sounds like a convoluted setup.
But then again, you might not have time to redo a database from scratch.
In your state, like in your form, you can create code to show/hide objects (controls).
In design mode, right-click and then create the event code, the code generator.
You choose the open() event and there you put the appropriate code, like:
if vchek2=true then
me.texte3.visible=true
.....
else
me.texte3.visible=false
.....
end if
Of course, this needs to be adapted.
For the "big hole in the middle" as you say, I don't really see how you have just one quote table. The use of sub-reports was definitely indicated.
If not, but it’s honestly a hack, you can use the above code to position your objects.
So, if your texte3 is not visible, you need to "move up" your texte4, with its properties:
if vchek2=true then
me.texte3.visible=true
me.texte4.top=
....
But that’s a hack...
Give me the structure of your tables, there might be a simpler way.
See you soon
--
When Jimmy says what’d I say, I love you baby
It’s like saying, the whole province sings in English.-
-
Anonymous user@françoisHi,
Sorry, but I'm at work and I'm off this evening, so I have quite a few things to wrap up.
Either you reduce your labels as much as possible and stack them on top of each other; they'll then be almost at the same height (when reduced, they'll be about 1 mm in height).
You set their 'autoextensible' property to yes, does it work (not tested)?
Or, you leave them as is, and in the code you used to make your labels visible/invisible, you adjust the properties to display them higher or lower in the state (ME.E2.Top=7.55 for example).
See you later
--
When Jimmy says what’d I say, I love you baby
It’s like saying, the whole province singing in English -
françois@Anonymous userThank you for taking the time to respond to me DHU, even during your vacation!!! Enjoy your vacation then!!!
As for your code in your second solution, I'm not quite sure where to insert it. My code is as follows:
If Forms!P!verso_pretstaion.Form!CB_repas = -1 Then
Date_repas.Visible = True
Else
Date_repas.Visible = False
End If
The problem is also that 7.55 is fine if only the previous line is inactive... but what if it were the 4 previous lines?
I need to be able to say:
if checkbox 1 is inactive then label 2 takes the place of label 1
and if checkbox 1 is active, checkbox 2 is inactive, checkbox 3 is inactive, checkbox 4 is active, label 4 takes the place of label 2...
But it's easier said than done... -
Anonymous user@françoisThank you,
Yes, we should test the possibilities, and it's not easy and it's not clean.
Have you tried the first solution? (minimize the labels as much as possible and set their 'autoextensible' property to yes)
See you later
--
When Jimmy says what’d I say, I love you baby
It's like someone would say, the whole province singing in English -
françois@Anonymous userHi HDU, sorry for this absence... ah, vacations...
I tried your solution of sticking the labels together and making them auto-resizable...
Several things: we cannot make the labels auto-resizable but only the text boxes... which is problematic in my case...
On the other hand, I tried with text boxes but that doesn't solve the issue... I end up with 2 text boxes almost on top of each other if I validate both...
I then went a bit higher up in the forum and reread one of your posts that said this:
""So, if your text3 is not visible, you need to "raise" your text4, with its properties:
if vchek2=true then
me.text3.visible=true
me.text4.top= ""
I wanted to know where to put this property so I can try.
On the other hand, will the "top" raise the text up to the previous text? Are you sure it won't just raise it to the top of the page?
Finally, I also saw a message where you told me that the subreport was just right... I don't know anything about subreports. Is it difficult to get started?
Thanks once again...
-
-
Breizhinours35I sincerely appreciate your help, but I can't send you the database because it is part of software with access code. So if I send it to you, you won't be able to open it....
Let me know if I'm on the right track:
In the table of my quote form, I have "name, first name... (of the client); AN8, PT4... (which correspond to the product, price...) ....
I added several checkbox columns to this table that I named VCHEK1, VCHEK2, VCHEK3, VCHEK4
In my form, I added an "existing field" and I dragged from my table VCHEK1, VCHEK2...
Then I created a report, and it's in this report that the text corresponding to the VCHEK1 checkbox should appear if I checked it. And that's where I'm stuck.... Furthermore, I would like that if I check boxes 1 and 3, the corresponding text in the report appears one after the other, without a big gap in the middle where there would be text 2
So that's it, and thanks again. -
Anonymous userWhat I’m proposing is that you send me your zipped database.
If you’re worried about your data (I’m not a crook lol), make a copy and empty the “sensitive” tables.
I'll have a better look "visually" because right now it’s blurry!
My email is in my profile.
However, I won’t be able to look at this until Monday afternoon, I’m heading off for the weekend.
See you!
--
When Jimmy says what’d I say, I love you baby
It’s like they say, the whole province singing in English. -
Breizhinours35uh... it would be a bit long to describe because I didn't design the database. There are 50 tables and just as many forms and queries, possibly...
Let me explain:
The database was created to manage equipment rental. Basically, it manages a client file, manages the stock of equipment, and issues quotes and invoices...
I want to make a quote. So I open a form where I enter my client, my products... and I generate the quote (document)
Everything works well, but in addition to that, I want to add those little checkboxes in my form that I can check or not. Then I press a button, and it generates the corresponding document with the text from checkbox 1 and 3 displayed because I checked box 1 and 3 and the text from checkbox 2 not displayed because I didn't check checkbox 2 for this specific quote.
Well, it may seem a bit complicated like that, but it would be very useful to me...
Thank you -
Anonymous userRe,
In my opinion, there is already a design issue...
For the opposite effect as you mentioned, the code I gave you should work. Obviously on the form.
Let us know what tables you have and what the database is for, in short, what you want it to manage.
Catch you later
--
When Jimmy says what’d I say, I love you baby
It’s like saying, the whole province singing in English -
Breizhinours35Hi and thanks for this initial information... I see things more clearly
The issue is that, here’s what I would ideally like to do:
I have a form that is part of a pre-built database.
On this form, I have checkboxes with titles for example:
chkbox 1: meals
chkbox 2: hotel
chkbox 3: travel
I want to choose in this form what I want to display but on a corresponding report and not on the form. The text described in the report is more complete than on the form, like "provide for 5 meals"
With the code you gave me, it makes it visible on the form. Moreover, it actually makes it invisible and it doesn’t reappear afterwards. I would like it to have the opposite effect as well.
Even better, I would like that if I check box 2, the meals are displayed at the top of the report and not in the middle.
Thank you for your help -
Breizhinours35Hello, three years later....
I'm brand new to Access but super motivated!
I'm working in Access for equipment management. The database has already been created, but not by me.
I would like to add this to the database: when I check a "checkbox" on a form, it displays text. If the box is not checked, it doesn't display.
Another condition: On my main form, I have all the texts that are displayed, so I can find my way around. When I check the corresponding box on this form, I want it to display on a report created specifically for that purpose.
I've already created my table, my form, and my report, but I'm a bit overwhelmed by the queries and relationships... I need a little help....
Thank you for your responses.-
Anonymous userHello,
In your form, in creation mode, right-click on the checkbox that should trigger the display or disappearance of the text, select "create event code," code generator if it asks you. Normally, Access will offer to assign code to the 'click' event (box at the top right) of the checkbox (top left).
That's what you want --> to do something when the user clicks on the checkbox.
You want to display or hide some text. Where is this text? In a text box? A label?
In any case, you know the name of the control that contains the text. It's called "texte1."
So, in the click event of your checkbox ("cocher1" for example), you put:if texte1=true then 'if the box is checked me!texte1.visible=true 'we display the text zone texte1 else me!texte1.visible=false end if
For your other question, I didn't quite get it! Apparently you have checkboxes on a form and you want these boxes to appear on a report?
If that's the case, do your boxes correspond to your fields in one (or several tables)?
I’m waiting for your answer to guide you.
See you soon
--
When Jimmy says what’d I say, I love you baby
It's as if the whole province is singing in English.
-
-
Anonymous userHello,
This should help you: https://grenier.self-access.com/?post/2007/09/05/Listes-deroulantes-liees
See you
--
When Jimmy says what’d I say, I love you baby
It’s like they say, the whole province singing in English -
younesHi everyone, I'm new to the forum
I have a problem with combo boxes, actually I would like to display a list based on another list, more specifically:
when choosing an item from one combo, the items in the second combo should change. I tried using a query but it doesn't work. And this in the same form (Access 2003) -
romstek31```html j'ai le même problème, j'ai mis mon code dans Current et je veux que si une date n'est pas saisie alors mon champ est activé, sinon non et ça ne marche pas :s
Private Sub Form_Current() If Not IsNull([dateValidPlanMinute]) Then [remarqueNonValid].Enabled = True Else [remarqueNonValid].Enabled = False End If End Sub
```-
domik
Private Sub Form_Current() If Not IsNull(dateValidPlanMinute) Then [remarqueNonValid].Visible = True Else [remarqueNonValid].Visible = False End If End Sub
you also need to put this code in the BeforeUpdate event (Cancel As Integer) as HDU mentionedPrivate Sub dateValidPlanMinute_BeforeUpdate(Cancel As Integer) If Not IsNull(dateValidPlanMinute) Then [remarqueNonValid].Visible = True Else [remarqueNonValid].Visible = False End If End Sub
-
romstek31@domikThank you very much, it's working ;)
-
-
-
- 1
- 2
Next