Solved

MS Access issue with "complex" expression

Posted on 2014-09-08
9
187 Views
Last Modified: 2014-09-09
This query has worked for a long time - but suddenly is throwing this error
error message
This is the query and the criteria coming from a form input
query
This is the data in the table I am querying
table data

On the form the user is entering an ending date like 08/31/14. The query had been able to translate that to 08 2014 - and the results were correct.    I don't know why I'd suddenly be getting the "too complex" error.    I reasoned that I could change my query to look at the posting-dt column instead of post-period and post-year, but I cannot since some records have a posting date that is not the same as the post-period.

I tried adding two new input field for the user to enter a post-period and post-year to use that as the criteria instead of the expression, but that did not work (returned in correct number of records).

I'd really like for this query to work as it has all along. Can an expert suggest a fix for this or point out why it may be failing?
0
Comment
Question by:Sue White
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 25

Expert Comment

by:chaau
ID: 40311193
I think you need to use "/" as a separator to match the Format:
CDate(Format([post-period] & "/" & [post-year], "mm/yyyy"))

Open in new window

BTW, next time please try to paste the actual code into your question instead of pictures.
0
 
LVL 25

Expert Comment

by:chaau
ID: 40311201
Having said that, I would suggest the enhancing the expression even further. It looks like you have not specified the day component of the date. I suggest you use dateSerial Access function to properly define the date from chunks:
'1st day of month
DateSerial([post-year], [post_period], 1)

Open in new window

With the help of dateAdd you can convert this date to the last date of month:
' Last Date of month: first add 1 month then subtract 1 day
DateAdd("d", -1, (DateAdd("m", 1, DateSerial([post-year], [post_period], 1)))

Open in new window

0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40311435
First, use this expression to create your date as the first day of the period directly:

    DateSerial([post-year], [post_period], 1)

Then, add your form reference as a parameter in the query. Specify data type Date. This is the key to solve your issue:

    [Forms]![frmMiscellaneousTab]![frmMiscellaneousAcct]![EndingDate]

or as:

    [Forms]![frmMiscellaneousTab]![frmMiscellaneousAcct].Form![EndingDate]

/gustav
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Sue White
ID: 40312678
Thank you both for your replies.  I did not author this query, so I cannot claim to fully understand it why it was created as it is.   The goal is for the query to generate results where the ending date the user enters is less than or equal to the values in the columns post-period and post-year.    I understand this is trying to concatenate the post-period and post-year into a date format (CDate(Format(([post-period] & "  " & [post-year]),"mm/yyyy")))  - and I see the value in chaau's suggestion to make this:
(CDate(Format(([post-period] & "/" & [post-year]),"mm/yyyy")))

I created a new simple query to see what results I get from:

SELECT DateSerial([post-year],[post-period],1) AS SerialFunc, (CDate(Format(([post-period] & "/" & [post-year]),"mm/yyyy"))) AS CDateFunc

and they both produce the same results
Expression Results
That's good, but I don't understand how I use that to filter the results from the table if the user enters 8/31/14 as the ending date and it needs for find all the records where the post-period & post-date are less than or equal to 8/31/14,

why or how I would use DateAdd function or Gustav's comment to specify the data type of Date.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40313007
How about this:  
Test Query
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 40313024
DateSerial is the function to use when you have the separate year, month, and day parts. Other methods can be used but will be more convoluted.

If you need to filter on records earlier than the last date of the period, again DateSerial is the direct method:

Use this expression to create your date as the last day of the period directly:

     DateSerial([post-year], [post_period] + 1, 0)

Note the subtle use of zero for the day.
Then, add your form reference as a parameter in the query. Specify data type Date. This is the key to solve your issue (the error message):

     [Forms]![frmMiscellaneousTab]![frmMiscellaneousAcct]![EndingDate]

 or as:

     [Forms]![frmMiscellaneousTab]![frmMiscellaneousAcct].Form![EndingDate]

 /gustav
0
 

Author Comment

by:Sue White
ID: 40313055
Ah I see Gustav - yes that does work!
Helen - I did initially try a query as you were suggesting but I ended up with an incorrect number of records.  My real query is using grouping and some other expressions that I didn't include in this ticket for simplicities sake.  I knew the issue was with the CDate() function.  

Thank you to all the experts that replied - I apprecriate your guidance.
0
 

Author Closing Comment

by:Sue White
ID: 40313058
I appreciate the explanation given!
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 40313064
You are welcome!

/gustav
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Balance After Payment 12 62
Database (Access Table) Security Access 8 60
Cant delete records in query 8 50
I really need your help with access query 9 33
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question