Results 1 to 10 of 10
  1. #1
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91

    To show/hide textfields depending of the value of other textfields

    Hi, everyone. This is my first post.



    I am creating a report that shows a chemical "recipe". Ingredients must be added in a form in % or in quantitative units (grams, ml...). There are two different fields.

    The report must show the % label only if the % field has data, and it must show the units field only if the gram field has data as well.

    I tried several ways with this expression and similars:
    Code:
    ...Detail format...
    
    If Me.Percentage > 0 then
    Me.labelPercentage.visible = true
    else
    me.labelpercentage.visible = false
    End if
    But I always get an error.

    I guess that the problem is on the first line, because thats the line that always gets the error ("it has no value")

    Can anyone help me?

    Notice that the property could change between lines, I mean: for the same formula, some ingredientes can be wrote in % and others in ml or g.

    Thanks

  2. #2
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Change

    If Me.Percentage > 0 then

    To If Len(Me.Percentage) Then

    If there is any value then this will return True. If Blank (ZLS) or Null it will return False.

  3. #3
    SFC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    47
    Create two labels one for each, put one one top of another in your report.
    Try using a macro, click on the page header, then in the properties sheet select the Event tab, then on the "On print" use the pulldown and select macro builder.
    In the marco page, use the pulldown and choose "If" to create an if statement. Next, start typing the name of the textbox that will dictate what label to show, as you type access will show you a list of your available textboxes and labels. After you set the criteria for the textbox (see my attachment) you use the pulldown menu and choose "Set Property". Then in control name type the label you want to hide, in the property box start to type visible, (access completes the spelling), and finally in the value box, type False. this will hide the label when the condition for the textbox is met.

  4. #4
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by Rainlover View Post
    Change

    If Me.Percentage > 0 then

    To If Len(Me.Percentage) Then

    If there is any value then this will return True. If Blank (ZLS) or Null it will return False.
    Thank you, Rainlover.

    I wrote this code:
    Code:
    If Len(Me.Porcentaje) Then
    Me.SimboloPorcentaje.Visible = True
    Else
    Me.SimboloPorcentaje.Visible = False
    End If
    
    If Len(Me.Gramos) Then
    Me.UdsPQ.Visible = True
    Else
    Me.UdsPQ.Visible = False
    End If
    It says
    Error 2427.

    You specified an expression without value.
    Quote Originally Posted by SFC View Post
    Create two labels one for each, put one one top of another in your report.
    Try using a macro, click on the page header, then in the properties sheet select the Event tab, then on the "On print" use the pulldown and select macro builder.
    In the marco page, use the pulldown and choose "If" to create an if statement. Next, start typing the name of the textbox that will dictate what label to show, as you type access will show you a list of your available textboxes and labels. After you set the criteria for the textbox (see my attachment) you use the pulldown menu and choose "Set Property". Then in control name type the label you want to hide, in the property box start to type visible, (access completes the spelling), and finally in the value box, type False. this will hide the label when the condition for the textbox is met.
    Hi, SFC.

    Sorry if I didn't understand you very well (i'm spanish). I got lost when you told me to choose "if" from a pulldown... I don't find it... and I cannot find as well your attachment.

    Can you just put the code?

    thx

    Maybe I could used some kind of conditional format turning the text into white. Anyway... I never used that functions before and I will be grateful if I get some more help :-/

  5. #5
    SFC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    47
    Sorry, I forgot to attach it, here it is:
    From the properties sheet in Access, select the event tab. In the event tab there will be a list that you can choose when the event will happen. In this case you should choose "On Print" so click in the box to the right of "On Print" (see the second attachment). A Builder dialog box appears asking what type of Builder you want to use, choose "Macro Builder". A new window will open for you to create a macro. This is different than writing code so I really can't write it here, try to follow my previous instructions and write back if you get stuck and I will try to help. There may be a better way to hide the the labels but this worked for me.

  6. #6
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    Quote Originally Posted by SFC View Post
    Sorry, I forgot to attach it, here it is:
    From the properties sheet in Access, select the event tab. In the event tab there will be a list that you can choose when the event will happen. In this case you should choose "On Print" so click in the box to the right of "On Print" (see the second attachment). A Builder dialog box appears asking what type of Builder you want to use, choose "Macro Builder". A new window will open for you to create a macro. This is different than writing code so I really can't write it here, try to follow my previous instructions and write back if you get stuck and I will try to help. There may be a better way to hide the the labels but this worked for me.
    Hi, SFC. This time I found the menu you were describing, an i learnt to use it. But I still can't make my report work.
    When I try to cast the preview using the form button what I get is a report with no data.

    You never told me what to put on the criteria box. I used IsNull(). Is this correct? I guess not...

    Thanks a lot

  7. #7
    SFC is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2011
    Posts
    47
    You can try something like this:
    if Nz([GramField])
    setProperty
    Control Name [percentLabel]
    Property Visible
    Value True
    Control Name [UnitLabel]
    Property Visible
    Value False
    Else
    Control Name [percentLabel]
    Property Visible
    Value False
    Control Name [UnitLabel]
    Property Visible
    Value True

    So if the gram field is empty it will show the Percent label likewise if the gram filed is not empty it will show the Units label.

    You could also have another record in your report (say Unittype) so if units is used then unittype equals 1 and if percent is used then unittype equals 0. Then use the following:
    if [unittype] = "1"
    setProperty
    Control Name [percentLabel]
    Property Visible
    Value True
    Control Name [UnitLabel]
    Property Visible
    Value False

  8. #8
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Do you have a Control in the Form called Percentage.

  9. #9
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    First of all, I must apologize because empty reports were caused by query error, not code.

    After solving this I tried both with SFC's and Rainlover's and unsucceded.

    if Nz([GramField])
    This syntax must not be correct. It says must have this format: Nz(variant, [valueifnull] ).

    WHAT I DID:
    I changed the query adding the units at the end of the number, and in the condition I used the text of the alone units. It worked (it worked on the detail_format section)

    It's a good solution for %, but not for quantitative. Because I must specify in the "If" all the different units I am using, and if i add more units in the future I'd have to change the code.

    Thank you very much guys. I still accept suggestions.

  10. #10
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows 7 64bit Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Just for clarification I suggested Len not Nz.

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

Similar Threads

  1. Hide Access and show only my forms
    By mortenskipper in forum Access
    Replies: 8
    Last Post: 01-20-2016, 08:21 AM
  2. Show/Hide Form
    By sparlaman in forum Forms
    Replies: 5
    Last Post: 05-16-2011, 11:48 AM
  3. show subform depending on combobox
    By d_Rana_b in forum Programming
    Replies: 2
    Last Post: 03-15-2011, 05:09 AM
  4. Replies: 21
    Last Post: 12-29-2010, 01:30 PM
  5. Hide and show tekstbox
    By Patience in forum Access
    Replies: 3
    Last Post: 06-18-2010, 06:15 AM

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