473,387 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VBA noob Trouble with DateDiff in VBA application

the following is not returning a negative number even when the start date is later than the end date. Some help would be very appreciated! thank you -


Private Sub CommandButton1_Click()
If DateDiff("d", ConfigStartDate, ConfigEndDate) >= 0 Then
Range("ConfigEndDate").Value = Calendar1.Value
UserForm3.Hide
Else
MsgBox "End Date is Before start date"
End If
End Sub
Sep 28 '11 #1

✓ answered by Guido Geurs

This is working:
vb6 form with commandbutton and 2 textboxes

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim ConfigStartDate As Date
  3. Dim ConfigEndDate As Date
  4.    ConfigStartDate = Day(txtConfigStartDate.Text)
  5.    ConfigEndDate = Day(txtConfigEndDate.Text)
  6.    If DateDiff("d", ConfigStartDate, ConfigEndDate) >= 0 Then
  7.       'Range("ConfigEndDate").Value = Calendar1.Value
  8.       'UserForm3.Hide
  9.       MsgBox "End Date is AFTER start date"
  10.    Else
  11.       MsgBox "End Date is Before start date"
  12.    End If
  13. End Sub

2 1873
Guido Geurs
767 Expert 512MB
This is working:
vb6 form with commandbutton and 2 textboxes

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim ConfigStartDate As Date
  3. Dim ConfigEndDate As Date
  4.    ConfigStartDate = Day(txtConfigStartDate.Text)
  5.    ConfigEndDate = Day(txtConfigEndDate.Text)
  6.    If DateDiff("d", ConfigStartDate, ConfigEndDate) >= 0 Then
  7.       'Range("ConfigEndDate").Value = Calendar1.Value
  8.       'UserForm3.Hide
  9.       MsgBox "End Date is AFTER start date"
  10.    Else
  11.       MsgBox "End Date is Before start date"
  12.    End If
  13. End Sub
Sep 29 '11 #2
Thank you looking at your code I realized I needed to read the values for configstartdate and configenddate from the worksheet into a local variable before the operation, it works now.

probabaly basic stuff but just getting into VBA.
Sep 29 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James | last post by:
Hi I am having some trouble getting a asp page to load. Im a noob to the asp side. I have followed knowledege base Article 301305. I am running 2000 adv, IIS 5.0 I have the following...
4
by: John Smith | last post by:
Hi, I'm having trouble working out the best way of calculating the time difference between two times on the same day. The example I have found does return the hours (in this case 8) but forgets...
2
by: Contro | last post by:
Hi there! I hope you can help me! I have the following code: SELECT COUNT(Applications.) AS TOTAL FROM Applications WHERE DateDiff('d',,Date()) <6 AND = "Certificate"; Which returns the...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
3
by: John Wildes | last post by:
Hello All I have an application that has one form. I start the application using a Application.Run(New frmMain) command in Sub Main(). When I exit, the exit menu Item simply does a Me.Close ....
3
by: Marcel Saucier | last post by:
I have written a Console Application then created a shortcut to it on my desktop. I was able to minimize the DOS window when I click my shortcut so I dont see anymore the DOS window But, using...
1
by: damon.reynolds | last post by:
Hello. I am trying to write an expression to help me pull some data out of my database. We have a group of people travelling between two dates - and Unfortunatley for me, the rooms are...
5
by: Milan Krejci | last post by:
the thing is that descentant branches i dont want to expand do expand. $id variable contains an array of branches i want the program to go through (alcohol's id -beer id etc) function...
12
by: TofuTheGreat | last post by:
I did a group search and found hundreds of cases of problems with DateDiff(). I read through several dozen but they didn not apply to my situation. Not having the time to read through all of them...
16
by: double kanon | last post by:
hi i am having trouble with this paystub program i am working on. so the console is supposed to ask for the start time and end time then calculate the pay with the rate given. How can i enter the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.