Results 1 to 6 of 6
  1. #1
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    102

    DateAdd: add a formula to the number argument

    Hello,

    in a query I i'm trying to pull a number from a combobox in a formula so that it populates the "number" argument inside the DateAdd function, but I'm not having any success...

    this is inside the expression builder...


    Code:
    Between Now() And DateAdd("ww",[forms]![frm80Expiring]![lstWeeks],Now())
    I already tested the formula replacing the [forms]![frm80Expiring]![lstWeeks] by a simple number and it works as required, I just need to be able to select how many weeks to add to the filter...

    what am I doing wrong?

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    That syntax should work, I tested with same and it worked. Is the combo box weeks value based off of a table or did you type the values in? Are you sure your records have a date within that range?

  3. #3
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    102
    Quote Originally Posted by Bulzie View Post
    That syntax should work, I tested with same and it worked. Is the combo box weeks value based off of a table or did you type the values in? Are you sure your records have a date within that range?
    Thanks, I typed the values inside the listbox and yes, I'm testing with 20 weeks, when I typed the furmula writing the number 20, it did filtered correctly...
    I don't know if something in the parameters of the listbox (Event is empty):

    Click image for larger version. 

Name:	1.png 
Views:	8 
Size:	19.6 KB 
ID:	27441Click image for larger version. 

Name:	2.png 
Views:	8 
Size:	9.2 KB 
ID:	27442Click image for larger version. 

Name:	3.png 
Views:	8 
Size:	8.1 KB 
ID:	27443

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Test that you are getting the right value from the list box. select a value from the list, then In a query, try: x: [forms]![frm80Expiring]![lstWeeks]

    and see if the value matches what you selected in the listbox.

    Another idea is to create a new list box, substitute the name in your query and see if it works.

  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,652
    A shot in the dark, to make sure the value is seen as a number:

    DateAdd("ww",CInt([forms]![frm80Expiring]![lstWeeks]),Now())
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    epardo87 is offline Competent Performer
    Windows 7 32bit Access 2016
    Join Date
    Dec 2016
    Posts
    102
    Quote Originally Posted by pbaldy View Post
    A shot in the dark, to make sure the value is seen as a number:

    DateAdd("ww",CInt([forms]![frm80Expiring]![lstWeeks]),Now())
    thanks for your advice, I tested it and had no success using the same formulas


    Test that you are getting the right value from the list box. select a value from the list, then In a query, try: x: [forms]![frm80Expiring]![lstWeeks]

    and see if the value matches what you selected in the listbox.

    Another idea is to create a new list box, substitute the name in your query and see if it works.
    I did this and it retrieved me 0, what I did was to test several ideas in this column and what did the trick is to change the listbox to a combobox, I wanted to use the listbox so that the user could select the number of weeks using the up or down arrows, but I rather have it working regardless of the combobox...

    giving it a second thought, now I get it, when I use the arrows in the listbox, I left the number in display but it was never selected, that is why it retrieved me 0!! how fool am I!
    look at the form so that you see the issue (the first one is already a combobox, but the second one is a listbox with a number in display, but not selected) :
    Click image for larger version. 

Name:	4.png 
Views:	6 
Size:	40.2 KB 
ID:	27446

    Thanks for your help!

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

Similar Threads

  1. DateAdd - number causing trouble
    By LetsHope in forum Access
    Replies: 9
    Last Post: 11-18-2016, 08:33 AM
  2. Replies: 3
    Last Post: 03-24-2015, 04:42 AM
  3. Format Formula - Text as Number
    By Madmartigan in forum Queries
    Replies: 8
    Last Post: 03-04-2014, 03:23 PM
  4. Replies: 3
    Last Post: 07-12-2013, 11:53 AM
  5. Replies: 6
    Last Post: 08-23-2012, 05:06 AM

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