Results 1 to 3 of 3
  1. #1
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67

    Comparing a combo box column to today's date

    Hi,



    I have a combo box on my form called cboTermID, the 4th column of which is the date/time field from my table.

    I have the following code on the forms current property.

    If DateValue(me.cboTermID.Column(3))<=DateValue(now() ) Then
    Me.cboStatus.Enabled=True
    Else
    Me.cboStatus.Enabled=False
    End If

    This doesn't return the result I am looking for, meaning that whether the value of cboTermID.Column(3) is less than today's date or greater, the cboStatus remains enabled.
    However, I have tried creating two unbound fields called txtTest and txtNow and set their control source to =DateValue([cboTermID].[Column](3)) and =DateValue(Now()) respectively. Then I have changed the code to compare the unbound fields as follows

    If Me.txtTest <= Me.txtNow then
    Me.cboStatus.Enabled=True
    Else
    Me.cboStatus.Enabled=False
    End if

    This returns the result I want, meaning that cboStatus is enabled if txtTest is less than txtNow and disabled otherwise.

    I don't understand why the first method doesn't work. I don't see a difference, an would appreciate if someone can shed some light on it.

    Thanks in advance.

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    well ......Now() includes time also - - and so the compare maybe isn't working right....

    instead try Date() and see if that works......

  3. #3
    injanib is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    67
    Thanks for the suggestion, but you can see that my code only considers the integer part of Now() with DateValue(Now()). I have also tried Date, and the same thing happened.

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

Similar Threads

  1. Query Date without comparing time
    By Bosco in forum Queries
    Replies: 5
    Last Post: 06-28-2010, 03:59 PM
  2. Isolate Column in Combo Box
    By jgelpi16 in forum Forms
    Replies: 2
    Last Post: 05-06-2010, 12:52 PM
  3. Replies: 1
    Last Post: 04-15-2010, 02:07 AM
  4. Comparing Date with current Date
    By ds_8805 in forum Forms
    Replies: 7
    Last Post: 03-31-2010, 09:31 PM
  5. Set Calendar to default to today's date
    By RickM in forum Access
    Replies: 1
    Last Post: 02-22-2009, 04:51 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