Abs(olutely) wrong

kupe

Registered User.
Local time
Today, 11:27
Joined
Jan 16, 2003
Messages
462
If the date in txtEndDate is more than 28 days old, I need cboWork to read "Available".

The following doesn't work ... for some reason.

If Abs(DateDiff("d", Me!txtEndDate, Date)) >= 28 Then
Me!cboWork = "Available"

Be grateful for advice, Craftsmen.
 
Nothing wrong with that. Are you sure your textbox is called txtEndDate - you'll never know if you use late binding instead of early binding; and early binding is, in most situations, always better.

Early binding is using the . (dot) operator over the ! (bang) operator. Using the dot allows you to use the IntelliSense feature and makes the compiler smile as you can spot errors quickly. With late binding you will only find errors at runtime - at times, disastrous.

So let's see what we can do with your code:
Code:
If Abs(DateDiff("d", Me!txtEndDate, Date)) >= 28 Then
    Me!cboWork = "Available"

First, change it to early binding:
Code:
If Abs(DateDiff("d", Me.txtEndDate, Date)) >= 28 Then
    Me.cboWork = "Available"

I see what you are trying to do and can only see a couple of reasons as to why its not working:

  1. Your textbox is incorrectly referred to;
  2. Your combobox is incorrectly referred to:
  3. The textbox does not actually have a date value;
  4. The combobox's BoundColumn is not a Text data type.

If you are getting an error message what is it?
 
SJ, Thanks very much for going to all that trouble. All noted about early and late bindings. I didn't appreciate the difference between bang over period (early/late bindings) - or have forgotten it - so it's a lesson learned.

Yes, it was my mistake. I added the 'End If' to other EndIfs at the end of a few other IfElseThens, but found the fault. Now it goes well. Cheers, SJ, and many thanks.
 

Users who are viewing this thread

Back
Top Bottom