Results 1 to 2 of 2
  1. #1
    datsyuk is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    7

    Text box - formula to test against values for what to display

    I have a text box and what I hope to accomplish is test if a value (the current date) is equal to any of the value in a table and if it is equal to a value in the table then display the associated value with that value. So to be more clear. I have a text box. I want to test the current date off of a table that contains a list of dates and an associated number relating to that date. I want to display this number. I have accomplished this using a query subform; however as I am going to have multiple instances differing slightly I would rather take the text box route if possible.

    As i am more familiar with C to help explain written in C it would be:

    for(i=0; i<dateListEnd; i++)
    {
    if (dateList[i]=currentDate)
    {
    cout<<dateValue[i];
    }
    }

    I am just starting in VBA and not very familiar with it. I know I will need an iff statement (using Date() and Month()) to compare the two and the return value will be the associated value of whichever date matches.
    So again, the structure that I am looking for is something like this:



    for all entries in the table if date is equal to current date display associated value. There will only ever be one value in the table that is equal.

    THANKS!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    VBA might not even be needed.

    You could try DLookup in the ControlSource of textbox.
    =DLookup("[associated value fieldname]", "[tablename]", "[date fieldname]=#" & Date() & "#")

    This will not save the retrieved value to a table. That would require code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 12
    Last Post: 10-22-2012, 06:11 AM
  2. IIF formula in an unbound text box using date()
    By probablyjoel in forum Forms
    Replies: 3
    Last Post: 04-20-2012, 12:03 PM
  3. formula in text box problem
    By kwooten in forum Reports
    Replies: 7
    Last Post: 09-12-2011, 08:19 AM
  4. Replies: 1
    Last Post: 03-27-2010, 06:13 AM
  5. Keying in Test answers to Access DB from Written Test
    By CityOfKalamazoo in forum Access
    Replies: 3
    Last Post: 03-01-2010, 08:58 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