Results 1 to 6 of 6
  1. #1
    barkly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    23

    textBox Value making label visible

    Stumped on this – appreciate some help.



    I have a text box (txtPartSaleSum) in the footer of a form with a control =Sum(IIf([Partsale]="Yes",1,0))

    which simply sums the occurrences of the text value “Yes” in field PartSale on the form.

    I also have a label, (PartBaltxt2) also in the footer of the same form, which I wish to make visible if the sum value in the text box is >= 1.

    I just cannot get this sum value across to some simple code that would fire the label visible = true process.

    Code:
    Dim LPST2 As Long
     
         LPST2 = Me.txtPartSaleSum
     
     
    MsgBox "LPST2 Yes = " & LPST2
     
        If LPST2 >= 1 Then
     
           Me.PartBaltxt2.Visible = True
           
        End If
    (I can see the value of the sum in the text box but I cannot see a value other than 0 in the MsgBox debug aid).

    Don’t know whether I should be trying to execute this in On Current, On Open, On Load or where else - having tried many of the events unsuccessfully.

    Thanks in advance

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Simpler code structure:

    Me.PartBaltxt2.Visible = Me.txtPartSaleSum > 0

    I tried this. If I simply open the form, the label doesn't show. If I set a breakpoint on the code then open form, the label will show after stepping through code.

    Seems the code executes before all the data loads and stepping through code delays the code long enough for data to load.

    Why do you need this? Maybe we can come up with something else to accomplish. Maybe another textbox instead of label with an expression to display text or return Null (or empty string). Set the textbox as transparent BorderStyle and BackStyle and when returns Null, it won't be seen.

    =IIf([txtPartSaleSum]>0, "Show this text", Null)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    SteveH2508 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Location
    Chelsea, London, England
    Posts
    117
    Why not use a calculated text box to display (or not) the caption that you want? Lock it, remove TabStop and format it like your label. Set the controlsource to something like

    =IIf(Sum(IIf([Partsale]="Yes",1,0))>=1,"YourTextHere","")

  4. #4
    barkly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    23
    Hi June7 and SteveH2508,
    Thanks for your quick responses.

    June7, as you say the code executes before all the data loads. Why do I need this? When I have a value 'yes' in the [PartSale] field I conditionally format the row to a different colour. The label then when Visible was to describe briefly what the row meant when it was a different colour.

    Steve, yes I tried your suggestion and it works but it only turns the caption text on or off. The label colour formatings are always present which I was trying to avoid. ie if there are no 'yes's then the label would be visible = false. Can a text box self control itself? ie if its value < 1 then it is not visible, if it is > 1 then it is visible.

    Thanks again

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Did you try my suggestion to set the BackStyle and BorderStyle properties to Transparent?

    Conditional Formatting does not allow setting Visible property.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    barkly is offline Novice
    Windows XP Access 2003
    Join Date
    Aug 2011
    Posts
    23
    Hi June7,

    No I hadn't tried your suggestion at the time but I have now.

    I have ended up with this as the control of a text box -

    =IIf(Sum(IIf([Partsale]="Yes",1,0))>=1,"Part Sale of Initial Holding",Null)

    I thus have the best of yours and that of SteveH's in the one compilation.

    I was actually hoping to have the text box background colour the same as the colour of the line that I had conditionally formatted but I have made this transparent and so now the text has the same colour. This has turned out to be satisfactory.

    Thankyou to yourself and Steve for your interest - appreciated.

    barkly

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

Similar Threads

  1. Replies: 3
    Last Post: 03-23-2012, 11:21 AM
  2. Making a Command Buttong Visible/Invisible
    By Lupson2011 in forum Forms
    Replies: 3
    Last Post: 02-16-2012, 12:03 PM
  3. Textbox/label Visible
    By prawln in forum Programming
    Replies: 6
    Last Post: 05-20-2011, 01:57 PM
  4. Making subform field visible/invisible
    By Snufflz in forum Forms
    Replies: 3
    Last Post: 01-17-2011, 05:30 AM
  5. Making objects visible in a report
    By Lockrin in forum Reports
    Replies: 3
    Last Post: 04-12-2010, 07:06 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