Results 1 to 7 of 7
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862

    Auto insert criteria

    What I am attempting is to do some settings in the criteria of a control



    ChngReQry.Date_Closed is the control

    I would like to be able to insert the outcome of the following code:

    Date_Clos: IIf([Commex Date]>=Date(),"Between Date()-6 and Date",Date())

    How would I be able to have the Date() come out like #3/15/2016#

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    I don't understand your post. Date() is the PC's current date, by definition.

    The IIF clauses are: IF, True, False

    So as you have written: If Commex >= the PC's date is true then you are trying to display:"Between Date()-6 and Date" - - what is this suppose to be with the term 'between' and ending with the word Date?? Perhaps you should give an example....

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    How would I insert this into the criteria?

    If Settings_QRY.Type control does not equal "Field" then "Between Date()-6 and Date() is true and should be inserted into the criteria section of Query_QRY.mycontrol (red box) If it is false then Date() should be inserted. This then gives me a range for the query to look at.

    What I am trying to achieve is not having to go to several different queries and change the criteria - Pure laziness on my part I know.



    Click image for larger version. 

Name:	Criteria.PNG 
Views:	14 
Size:	3.8 KB 
ID:	24102

  4. #4
    NTC is offline VIP
    Windows 7 64bit Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    There are 2 approaches;

    a. build your query using SQL syntax in VBA (not query design view) with if/then logic as to which SQL clauses are to be used
    b. build 2 separate queries (in query design view), and use if/then logic to decide which query to use

    approach b is simpler and easier to manually test individual queries; but if you need a single record source for a form/report then one must do it via the first approach

  5. #5
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    OK,
    Simplified: I would put this in the Field:
    Date_Closed: IIf([Commex Date]>=Date(),Between Date()-6 and Date(),Date())

    How do I get access to recognize Between Date()-6 and Date() without making it a text in quotes? Text wouldn't work.

    Datediff, Dateadd wouldn't work I am assuming since I want to get records in a range, and these would enumerate what the range is.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If you want a string with the dates, you can concatenate the dates:
    Code:
    "Between " & Date()-6 & " and " & Date()
    or

    Code:
    "Between #" & Date()-6 & "# and #" & Date() & "#"

  7. #7
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862
    Thanks ssnafu, I'll give it a shot

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

Similar Threads

  1. auto-number not used on insert
    By DKP in forum Queries
    Replies: 5
    Last Post: 10-06-2014, 11:04 AM
  2. Replies: 4
    Last Post: 08-01-2014, 09:20 AM
  3. Auto insert of value
    By uk123 in forum Programming
    Replies: 15
    Last Post: 10-29-2013, 12:23 PM
  4. Replies: 6
    Last Post: 09-09-2011, 10:26 AM
  5. Replies: 4
    Last Post: 08-01-2011, 03:36 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