Results 1 to 5 of 5
  1. #1
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480

    Help understanding why a statement isn't true. oie.document.all.tags("input").value = date?

    So I am navigating a website, I've come across a situation where there could be multiple textboxes on the page. So I have a loop that is going to determine all the values of the "input" tags on the page. I want to only change the input boxes that have todays date in them.

    Code:
    futuredate = Format(Date + 7, "m/d/yyyy")
    Cnt = 0
    With oie.document.all
        For Each oCell In .tags("input")
                If oCell.value = "3/7/2016" Then
                    oCell.value = futuredate
                End If
            Cnt = Cnt + 1
            Debug.Print oCell.value & "-   Cnt is " & Cnt
        Next oCell
    End With
    Set oCell = Nothing
    And this works fine, makes the changes without any issues. Now, when I try to replace the hardcoded date with Date, the code never picks it up in the if statement, even though ocell.value and date are both identical in the immediate window.

    Code:
    futuredate = Format(Date + 7, "m/d/yyyy")
    Cnt = 0
    With oie.document.all
        For Each oCell In .tags("input")
                If oCell.value = Date Then   ' This is a true statement, even the formatting is the same. Why doesn't it work? 
                    oCell.value = futuredate
                End If
            Cnt = Cnt + 1
            Debug.Print oCell.value & "-   Cnt is " & Cnt
        Next oCell
    End With
    Set oCell = Nothing




    Any advice? Kind of stumped on this one.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Date returns a number internally, so try:

    If oCell.value = Format(Date, "m/d/yyyy") Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    The ocell.value might be text even though it looks the same as Date(), which is not text and will be represented according to your regional settings. The TypeName function may confirm this if you use it in a debug.print statement. The solution may be to coerce the value to a date (CDate), either directly or after assigning it to a variable. However, you must handle nulls or the cdate function will raise an error. Or you can concatenate date delimiters (#) into the string date, if in fact it is a string, before you compare it to Date().
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    Quote Originally Posted by pbaldy View Post
    Date returns a number internally, so try:

    If oCell.value = Format(Date, "m/d/yyyy") Then


    I can not believe that this was the problem. This worked great, thank you!

    Is it just me or is it silly that the return for Date and Format(date,) is different? I mean, they both debug.print the same... but yea.

    edit* a word

  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,521
    No, the Format() function always returns a string. Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 02-16-2015, 01:04 PM
  2. Replies: 3
    Last Post: 12-06-2014, 03:59 AM
  3. Suppress "Error" message following "Cancel = True"
    By GraeagleBill in forum Programming
    Replies: 7
    Last Post: 03-23-2014, 05:40 PM
  4. Replies: 2
    Last Post: 09-29-2012, 11:22 PM
  5. Replies: 2
    Last Post: 08-31-2006, 12:19 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