Results 1 to 3 of 3
  1. #1
    Ekhart is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jun 2016
    Posts
    80

    Help shortening code for Query Criteria

    I am trying to write a bit of code for a field in a query but am running in to length contraints. I did what I could to shorten the field names and the only other thing I can think of now to help is to shrink the text displayed by the code for each instance, but I would really rather avoid that if I can. [Alert] is an unbound field and not in the table. The problem is I am at my character limit for a field entry. Any suggestions on how to either shrink this one, or perhaps have 2 hidden fields that each make up half of the total script and then a third field that displays what is in either Alert or Alert2 fields? (There is more to the code, this is just what will fit currently)

    Code:
    Alert: IIf(([LA]="First Call" , "Second Call" Or [LA]="Letter Sent") And [AD] Is Not Null,"Apt Date, Check Last Action",IIf(([LA]="Packet Faxed" And [DA]<Date()-2 And [U]="Stat") Or ([LA]="Packet Faxed" And [DA]<Date()-10 And [U]="Routine"),"Check for Apt",IIf(([LA]="Uploaded to Choice" And [DA]<Date()-2 And [U]="Stat") Or ([LA]="Uploaded" And [DA]<Date()-10 And [U]="Routine"),"Check for Apt",IIf(([LA]="First Call" And [DA]<Date()) Or ([LA]="Second Call" And [DA]<Date()) Or ([LA]="Letter Sent" And [DA]<Date()-13),"Attempt to Contact",IIf([LA]="Scheduled" And [AD] Is Null,"No Apt Date",IIf(([LA]="Scheduled" And [AD]<Date() And [U]="Stat") Or ([LA]="Scheduled" And [U]="Routine" And [AD]<Date()-6),"Apt Date Passed",IIf(([LA]="Records Requested" And [DA]<Date()-6) Or ([LA]="Records Received" And [DA]<Date()-6),"Check Records",IIf([LA]="Awaiting Approval" And [DA]<Date(),"Check Approval",IIf(([LA]="Other" And [OD]<Date()) Or ([LA]="Other" And [OD] Is Null),"Other Date")))))))))


  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    I used to do this sort of thing (but never to this level) and kind of wore the success as a badge of achievement. I don't see it that way these days.
    My suggestion would be to convert all of this to a function and return it to your query field: Alert:myFunction(). If need be, you can pass parameters that relate to a query field.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    Try something like this. The function will calculate the value that you need in the query.
    Code:
    Private function fcnAlert()
    fcnAlert = Alert: IIf(([LA]="First Call" , "Second Call" Or [LA]="Letter Sent") And [AD] Is Not Null,"Apt Date, Check Last Action",IIf(([LA]="Packet Faxed" And [DA]<Date()-2 And [U]="Stat") Or ([LA]="Packet Faxed" And [DA]<Date()-10 And [U]="Routine"),"Check for Apt",IIf(([LA]="Uploaded to Choice" And [DA]<Date()-2 And [U]="Stat") Or ([LA]="Uploaded" And [DA]<Date()-10 And [U]="Routine"),"Check for Apt",IIf(([LA]="First Call" And [DA]<Date()) Or ([LA]="Second Call" And [DA]<Date()) Or ([LA]="Letter Sent" And [DA]<Date()-13),"Attempt to Contact",IIf([LA]="Scheduled" And [AD] Is Null,"No Apt Date",IIf(([LA]="Scheduled" And [AD]<Date() And [U]="Stat") Or ([LA]="Scheduled" And [U]="Routine" And [AD]<Date()-6),"Apt Date Passed",IIf(([LA]="Records Requested" And [DA]<Date()-6) Or ([LA]="Records Received" And [DA]<Date()-6),"Check Records",IIf([LA]="Awaiting Approval" And [DA]<Date(),"Check Approval",IIf(([LA]="Other" And [OD]<Date()) Or ([LA]="Other" And [OD] Is Null),"Other Date")))))))))
    End Function
    Then in your query:
    Code:
    Alert: fcnAlert()

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

Similar Threads

  1. Shortening if / dlookup >0 / then dlookup
    By Jack Russel in forum Modules
    Replies: 1
    Last Post: 02-19-2016, 03:01 PM
  2. Write the criteria of a query in the event code
    By Batraul in forum Programming
    Replies: 8
    Last Post: 12-26-2014, 04:08 AM
  3. Multiple Form Filter Criteria vba code
    By Moonman in forum Programming
    Replies: 6
    Last Post: 11-16-2013, 12:42 AM
  4. Code for using a list box for criteria in a form
    By tomnsd in forum Programming
    Replies: 7
    Last Post: 01-23-2013, 10:52 PM
  5. Replies: 3
    Last Post: 10-15-2010, 11:17 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