Results 1 to 10 of 10
  1. #1
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16

    Set Field 'Visible' property based on Field value in Report

    Hi folks.



    I have a field in a report which contains combined values i.e. =[D Med 1] & " " & [D Med 1 Dose] & "mg" & " " & [D Med 1 Freq]. I'm trying to set the field visible property to false if the field has no specific data in it, ie. only contains "mg" without the medication name or dose or frequency. The following code whilst not throwing up errors, isn't working:-

    Private Sub Report_Load()
    If Me.Discharge_Meds_10 Like "mg*" Then
    Me.Discharge_Meds_10.Visible = False
    Else: Me.Discharge_Meds_10.Visible = True
    End If
    End Sub

    Can anyone offer any help on where i'm going wrong?

    thanks in advance.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    I think you would need to do this on the OnFormat property assuming it's multiline report.
    If not conditional formatting to disable the control.

    An alternative would be to use the "propagation of nulls" so if you added the values together

    =[D Med 1] + " " + [D Med 1 Dose] + "mg" + " " + [D Med 1 Freq]

    any null value would make the result null, automatically hiding it.
    Last edited by Minty; 05-21-2019 at 05:05 AM.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    what does 'isn't working' mean?

    where is the Discharge_Meds_10 control? in the header? detail? Is your report continuous? If the control is in the detail section and the report is continuous then suggest try the detail onformat event instead

    You can also make the code much simpler

    Me.Discharge_Meds_10.Visible= not(Me.Discharge_Meds_10 Like "mg*")

    finally your code includes a space

    =[D Med 1] & " " & [D Med 1 Dose] & "mg" & " " & [D Med 1 Freq]. #

    so you probably need

    Like " mg*")

  4. #4
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16
    Thank you guys. It was the 'On Format' and the " mg*" that was the issue.

    Now if I have 10 'Med' fields and I want to apply the same rule for all 10 is it just a case of copying the code and updating the field number, ie. 1, 2 3 etc or does the code need to be varied?

    thanks once again for your comments.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Same expression. Copy/paste/modify.

    If you can manage the calc in textbox, would be better than VBA.

    Keep in mind, Format event does not trigger for ReportView, only PrintPreview or direct to printer.

    Multiple med fields is not a normalized data structure.
    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
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16
    Quote Originally Posted by June7 View Post
    Same expression. Copy/paste/modify.

    If you can manage the calc in textbox, would be better than VBA. Yep the calcs are done in the text box.

    Keep in mind, Format event does not trigger for ReportView, only PrintPreview or direct to printer.s.Yep am aware of that thanks.

    Multiple med fields is not a normalized data structure.
    It's working intermittently:Click image for larger version. 

Name:	DS ScreenShot.jpg 
Views:	13 
Size:	93.7 KB 
ID:	38477
    Click image for larger version. 

Name:	VBA.jpg 
Views:	12 
Size:	173.2 KB 
ID:	38478

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    Should post code as text between CODE tags, not an image.

    Don't see how that structure can work at all. Each control should be an independent If Then Else. However, If Then Else not needed. Use Ajax's one liner for each control

    Me.Discharge_Meds_1.Visible = Not Me.Discharge_Meds_1 Like " mg*"
    Me.Discharge_Meds_2.Visible = Not Me.Discharge_Meds_2 Like " mg*"
    ...

    Alternative:

    For x = 1 to 11
    Me("Discharge_Meds_" & x).Visible = Not Me("Discharge_Meds_" & x) Like " mg*"
    Next

    Or try Minty's expression in textbox and eliminate VBA.
    =[D Med 1] + " " + [D Med 1 Dose] + "mg" + " " + [D Med 1 Freq]
    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.

  8. #8
    Archer's Avatar
    Archer is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2019
    Location
    Down Under
    Posts
    16
    Quote Originally Posted by June7 View Post
    Should post code as text between CODE tags, not an image.

    Don't see how that structure can work at all. Each control should be an independent If Then Else. However, If Then Else not needed. Use Ajax's one liner for each control

    Me.Discharge_Meds_1.Visible = Not Me.Discharge_Meds_1 Like " mg*"
    Me.Discharge_Meds_2.Visible = Not Me.Discharge_Meds_2 Like " mg*"
    ...

    Alternative:

    For x = 1 to 11
    Me("Discharge_Meds_" & x).Visible = Not Me("Discharge_Meds_" & x) Like " mg*"
    Next

    Or try Minty's expression in textbox and eliminate VBA.
    =[D Med 1] + " " + [D Med 1 Dose] + "mg" + " " + [D Med 1 Freq]
    Ajax's one liner worked perfectly. Minty's option left the text of 'mg' visible.

    Thank you to everyone who offered help on this one gents.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,895
    I tested Minty's expression and "mg" is not displayed if any field is null. So, your fields must contain empty string if there is no value which would cause "mg" to display.
    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.

  10. #10
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,002
    Quote Originally Posted by June7 View Post
    I tested Minty's expression and "mg" is not displayed if any field is null. So, your fields must contain empty string if there is no value which would cause "mg" to display.
    Thanks June - I assumed that was the why there was the spare "mg" in the sample screen print. Rogue data.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Replies: 2
    Last Post: 04-30-2019, 03:44 AM
  2. Replies: 7
    Last Post: 06-07-2018, 04:49 PM
  3. Replies: 17
    Last Post: 08-03-2017, 06:08 PM
  4. Replies: 2
    Last Post: 09-17-2015, 12:38 PM
  5. Replies: 6
    Last Post: 09-27-2011, 04:39 PM

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