Results 1 to 9 of 9
  1. #1
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32

    Question Replace nulls in report with placeholder string to indicate no data

    Hello folks!
    I am struggling my way though creating some reports. They were created by saving forms as reports since they are not grouped/aggregated like many reports are. An example recordsource is below. Most of the fields are short or long text fields and they are not always filled out by the user, which is fine as not all fields are always applicable. I have the controls set to "can grow" and "can shrink" since the amount of text in them varies widely. However due to this when the control is null that text box disappears and the report's formatting gets jumbled. When the report is opened I would like the null text boxes to display " --" to indicate that no data was entered there, rather than the viewer wondering whether something is missing. (I've tried doing this in the format property of the control and/or of the table field but have discovered that causes truncation of text over 255 characters for long text fields.) Through many searches and code attempts I have arrived at the solution of doing something in the report's "on load" event such that it checks if a control value is null and puts something there if it is, however I am having trouble doing this. I am thinking I should use a Nz () or IIF () function (?)

    So far I'm thinking something like this but it doesn't work and I wouldn't know how to efficiently string together a statement for multiple controls:

    Private Sub Report_Load()
    Dim Nills As String
    Nills = Nz(Me.txtPulseQual, " --")
    End Sub

    Not sure if I'm on the right track. Any help appreciated!!!

    Recordsource example:
    SELECT ExamTable.ExamDate, ExamTable.CauseforExam, ExamTable.[Animal/GroupAge], ExamTable.Weight, ExamTable.WeightUnits, ExamTable.BodyTemp, ExamTable.TempUnits, ExamTable.RespRate, ExamTable.HeartRate, ExamTable.PulseQuality, ExamTable.CapillaryRefillTime, ExamTable.VitalsNotes, ExamTable.HistoryCheck, ExamTable.AppearanceGait, ExamTable.HEENM, ExamTable.Samples, ExamTable.DiseaseSigns, ExamTable.AnimalIDFK, ExamTable.ExamAutoID, ExamTable.ImpressionDiagnosis, ExamTable.TreatmentPlan, ExamTable.ReevaluationPlan, AnimalTable.FacilityAnimalID, AnimalTable.Species, AnimalTable.CommonName, AnimalTable.Sex
    FROM AnimalTable INNER JOIN ExamTable ON AnimalTable.AnimalAutoID = ExamTable.AnimalIDFK;

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Hi Girraffa,

    Would something like this work (assumes your controls that are shrinking are text boxes):
    Code:
    Private Sub Report_Open(Cancel As Integer)Dim ctrl As Control
    
    
    For Each ctrl In Me.Controls
        If ctrl.ControlType = acTextBox Then
           ctrl.Value = Nz(ctrl.Value, "---")
        End If
    Next ctrl
    
    
    Set ctrl = Nothing
    
    
    End Sub
    Cheers,
    Vlad

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    doesnt the fact that there is no data in the cell indicate there's no data?

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    I have the controls set to "can grow" and "can shrink"
    What about setting "Can Shrink" to No?

  5. #5
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    Vlad,
    I tried that but it gets stuck on
    ctrl.Vaue = Nz(ctrl.Value, "---")
    with error: 2424
    "the expression you entered has a field, control, or property name that Microsoft Access can't find."
    Any ideas?
    thank you!

  6. #6
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    Yes the absence of data implies no data, but for display sake and end users who are not familiar with database inner-workings I would like to be explicit about that. If I set "can shrink" to no I will end up with big empty areas in the report. I suppose I could just make the controls disappear when the values are null but ideally I would be able to insert some placeholder text--this feels like something that should be possible

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Maybe going out on a limb but want to say that using VBA to set Value property of textbox in report won't work. Ever. At All. Period.

    I avoid long text (memo) type field because of their quirks.

    Does this work in ControlSource:

    =IIf(IsNull([fieldname]), "--", [fieldname])
    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
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    June,
    It sure does!! Thank you! yes I am learning more and more about the quirks of the long text fields, oi. Good to know about VBA. My next idea was to make text boxes that only appeared when those fields were null and put what I wanted in those...this is much easier. Thanks again!

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Let me qualify my earlier statement. VBA cannot directly set Value property in report. However, the ControlSource can call a VBA UDF (user defined function).
    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.

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

Similar Threads

  1. Replace data when running report
    By Ekhart in forum Reports
    Replies: 1
    Last Post: 06-25-2016, 03:35 AM
  2. Automatically replace NULL with zero string
    By tylerg11 in forum Access
    Replies: 13
    Last Post: 09-16-2013, 04:34 PM
  3. Issue Using Replace in SQL String
    By starryNight in forum Programming
    Replies: 15
    Last Post: 06-03-2011, 01:24 PM
  4. Replace a string/text in ms-access db
    By anziga in forum Queries
    Replies: 4
    Last Post: 12-31-2010, 06:40 PM
  5. replace characters in a string
    By blazixinfo@yahoo.com in forum Access
    Replies: 6
    Last Post: 08-06-2009, 03:36 PM

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