Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23

    Remove Error Line from Report

    Hi all,



    I have a report which is meant to show upcoming appointments with some information about the appointment (day, date, time, and which eye the appointment is for). All information in this report is drawn from one query.

    The table in which dates are stored (Appointment) allows storage of two different types of date (ApptDate and RevDate), each of which need to be displayed separately. I've circled these in red in the picture of the query design below. The same table stores information about which eye the appointment is for. I've circled this in blue. Every entry in the Appointment table will have a value of either Left or Right for eye, however, each individual entry can have a value only for ApptDate or RevDate not both.

    This is causing a problem in my report. In the section of the report pictured below I only want to show appointment information where there is an ApptDate, and not where there is a RevDate. The report is putting in a line at the start because there is a RevDate value in a row in the Appointment table containing Eye information. When it tries to calculate the Weekday it returns an error because there is a null value in the ApptDate.

    Is there a way to prevent the report from including rows where there is no ApptDate value?

    Any help would be appreciated.

    Thanks, Adrian.

    Report:
    Click image for larger version. 

Name:	Report.jpg 
Views:	13 
Size:	34.7 KB 
ID:	29862

    Query:
    Click image for larger version. 

Name:	Query.jpg 
Views:	13 
Size:	96.2 KB 
ID:	29863

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Reports are not to be used for getting the data right, this must be done in the query. Do all the calculations there before coming in to the report.

  3. #3
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    The query is where I've been trying to fix it.

    But I don't know of any way in a query to make a field return as null based on the value of another field. That would solve the problem.

    Ie. If ApptDate = Null, Day = Null, Time = Null, Eye = Null.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    DayOfAppt: IIf(IsNull(ApptDate),Null,day calculation)
    If ApptDate is null then set DayOfAppt to null, otherwise do the day calculation (not sure how you are doing this part but it will be the same).

    These are reserved words, Day, Time, etc. You need to change them in the query.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Try this in the criteria of ApptDate:

    Is Not Null
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    Quote Originally Posted by pbaldy View Post
    Try this in the criteria of ApptDate:

    Is Not Null
    Wouldn't that enforce a value in ApptDate? I need it to be null when there is a value for RevDate, and vice versa.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Sorry, I must have misunderstood "I only want to show appointment information where there is an ApptDate".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    Quote Originally Posted by aytee111 View Post
    DayOfAppt: IIf(IsNull(ApptDate),Null,day calculation)
    If ApptDate is null then set DayOfAppt to null, otherwise do the day calculation (not sure how you are doing this part but it will be the same).
    Hi, and thanks for the help. Quick question, would that set the data in the tables to null when the query is run, or would it just show the results of the calculation as null without affecting the data in the table?

    The SQL I'm using for the calculation looks like this:

    Select ... WeekdayName(Weekday(Appointment.Appointment_Date-1)) AS DayName, Appointment.Appointment_Date AS ApptDate, ... From ... ;

    So updating it to include your suggestion, should it look like this?

    Select ... If (IsNull (Appointment.Appointment_Date), Null, WeekdayName(Weekday(Appointment.Appointment_Date-1))) AS DayName, Appointment.Appointment_Date AS ApptDate, ... From ... ;

    These are reserved words, Day, Time, etc. You need to change them in the query.
    They all have different names in the query. That is just what they're represented as on the report.

  9. #9
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    Quote Originally Posted by pbaldy View Post
    Sorry, I must have misunderstood "I only want to show appointment information where there is an ApptDate".
    No worries. I appreciate the input.

  10. #10
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I need it to be null when there is a value for RevDate, and vice versa.
    A data constraint such as that should be enforced at the form level, when data is being entered or updated. If you have to do it at the query level, it means you have invalid data (for that constraint)

  11. #11
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    Quote Originally Posted by John_G View Post
    A data constraint such as that should be enforced at the form level, when data is being entered or updated. If you have to do it at the query level, it means you have invalid data (for that constraint)
    I have enforced this at form level. I have written a macro that erases data from one if data is entered into the other.

    This means that if data is entered for RevDate on the form, ApptDate will be null in the table, which is the way I want it.

    The issue this creates, however, is that when I try to use ApptDate to calculate the WeekdayName it returns an error in rows where there is no information in the ApptDate field. This shows up as an appointment record on the report with data for the Eye field, an error for the Day field, and two null fields for date and time.

  12. #12
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Note the two i's - IIf, not If. The syntax looks correct.

  13. #13
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    Quote Originally Posted by aytee111 View Post
    Note the two i's - IIf, not If. The syntax looks correct.
    Mea Culpa, I thought that was a typo. I'll give that a try so, thanks.

  14. #14
    AdiDoyle is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Location
    Ireland
    Posts
    23
    Hey aytee111,

    That worked perfectly. Thanks so much for the insight.

    Best,
    Adrian.

  15. #15
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In you original query, try something like this for ApptDate:

    Iif(not IsNull(Appointment_Date), Appointment_Date, Appointment_RevDate)

    In English: If the Appointment Date is not null, then use that date, otherwise use the Rev Date.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-03-2015, 05:53 PM
  2. Replies: 2
    Last Post: 03-23-2015, 08:32 AM
  3. Replies: 4
    Last Post: 07-12-2014, 02:02 PM
  4. Error Declaring FK and PK on same Line
    By jo15765 in forum SQL Server
    Replies: 0
    Last Post: 01-21-2012, 04:29 PM
  5. DAO error in Set rst line...
    By tnt in forum Programming
    Replies: 2
    Last Post: 10-06-2011, 12:14 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