Results 1 to 7 of 7
  1. #1
    llmdb is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2023
    Posts
    3

    Making fields visible without having to refresh form

    Hello,
    I am new to Access and I can't find the answer to me question on the forum.
    I am creating a database for collecting data on experts. In a form, I have two fields: one field is "number of experts" and I have two other fields: "expertise of expert 1" and "expertise of expert 2". I want the "expertise of expert 1" field to appear when the "number of experts" field is equal to 1, and both "expertise of expert 1" and "expertise of expert 2" fields to appear when the "number of experts" field is equal to 2. I want the fields to appear as soon as I enter the number of experts. I have written the following code:


    If [number of experts] >= 2 Then[expertise of expert 2].Visible = TrueElse[expertise of expert 2].Visible = FalseEnd If
    If [number of experts] >= 1 Then[expertise of expert 1].Visible = TrueElse[expertise of expert 1].Visible = FalseEnd If
    I wrote this code in the "Current" property, and initially I had put it in the "On Click" property, but when I fill in the "number of experts" field, I have to refresh my form for the "expertise" fields to appear. I tried putting the code in the "Before Update" property, but that didn't work either...
    How can I achieve this? Is there a way to program automatic refresh, for example?
    Thank you for your valuable help.

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    First of all, if [number of experts] is 2,
    then the test
    [number of experts] >= 1 is true.

    Try putting your code in the after_update event of the [number of experts] textbox.
    You'll have to move out of the textbox for the after_update event to fire.
    Last edited by davegri; 06-02-2023 at 06:42 AM. Reason: addl

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    I understand that you are new to Access. A good database starts with good tables. Tell us more about the tables you have. Is your form and the "Controls" (you have fields in tables but you have controls on forms which may or may not be bound to the fields in the table/query that the form is bound to) bound to one of your tables.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Please use a normal size font
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Agree with davegri; with what you show, as long as the entry is greater than zero, no matter what number you enter the result will always be true for the second test. Also, don't confuse refresh with repaint, although you should not need Repaint method either. Set the visible property of the controls to No in design view. Then perhaps use

    Code:
    Me.[expertise of expert 1].visible = Me.[number of experts] = 1
    If Me.[number of experts] > 1 Then
      Me.[expertise of expert 1].visible = True
      Me.[expertise of expert 2].visible = True
    End If
    You might want to validate entries to ensure only +ve numbers (that means no text either) can be entered.
    Do yourself a favour and don't use spaces or special characters (save for perhaps underscore) in object names. Life will be easier if you simplify and shorten names as well.
    Last edited by Micron; 06-02-2023 at 07:53 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    llmdb is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2023
    Posts
    3
    Quote Originally Posted by davegri View Post
    First of all, if [number of experts] is 2,
    then the test
    [number of experts] >= 1 is true.

    Try putting your code in the after_update event of the [number of experts] textbox.
    You'll have to move out of the textbox for the after_update event to fire.
    Hello everyone, thank you so much for your quick answers and great help, I had put the code in the form event and not in the textbox event, now it works! and thank you for all the other advices! Can't wait to learn more about access and sorry for the weird font. Have a good one

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    Happy to help and thanks for the star !

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-07-2022, 09:57 AM
  2. Replies: 5
    Last Post: 08-14-2017, 02:19 AM
  3. How to condition Making Fields Visible in a Report
    By Juan1313 in forum Programming
    Replies: 2
    Last Post: 06-30-2017, 05:13 AM
  4. Making form header visible
    By Benton in forum Forms
    Replies: 1
    Last Post: 06-24-2016, 05:39 PM
  5. Replies: 4
    Last Post: 05-29-2013, 01:29 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums