Solved

Date picker returning strange values!

Posted on 2007-11-13
2
423 Views
Last Modified: 2013-12-26
Hi experts.

All night i have been puzzling over this one - it seems ridiculous to me but here goes.
I have a date picker called 'date_start_pick'. When i select a value from the picker, i want to return this date to a cell in a worksheet 'DATA STORE'. Now, although the msgbox in the code beneath are returning the CORRECT values for the day, month and year values of the date i select - the value that is returned to excel has the day and month values swapped. So if i select 1st November 2007 from the date picker - the value returned to my worksheet cell is 11/01/2007. This is completely messing up my script and cant fathom why it would do this!!

Here is my code behind the userform :

Public wksdata As Worksheet
Public wks_week As Worksheet
Public wks_OEE As Worksheet
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Private Sub analysis_return_button_Click()
Analysis_Userform.Hide
Startup_Userform.Show
End Sub

Private Sub Fault_Period_Toggle_Click()
OEE_date_start_pick.Enabled = True
OEE_date_start_pick.Format = dtpLongDate
OEE_date_start_pick.MinDate = wksdata.Cells(5, 1).Value
OEE_date_start_pick.MaxDate = wksdata.Cells(5, 2).Value - 1

End Sub

Private Sub OEE_Period_Toggle_Click()
'set the minimum and max dates on range selectors
OEE_date_start_pick.Enabled = True
OEE_date_start_pick.Format = dtpLongDate
OEE_date_start_pick.MinDate = wksdata.Cells(5, 1).Value
OEE_date_start_pick.MaxDate = wksdata.Cells(5, 2).Value - 1

'OEE_date_end_pick.MinDate = wksdata.Cells(5, 1).Value
'OEE_date_start_pick.MaxDate = wksdata.Cells(5, 2).Value
End Sub

Private Sub plot_charts_button_Click()

'Plot user defined period charts
If wksdata.Cells(6, 1).Value <> "" And wksdata.Cells(6, 2).Value <> "" Then
    If OEE_Period_Toggle = True Then
    Call OEE_Period_Chart
    End If
    If Fault_Period_Toggle = True Then
    Call Fault_Period_Chart
    End If
Else
MsgBox ("Select the upper date for Machine OEE Analysis")
Exit Sub
End If

' Call weekly charts
If OEE_Weekly_Toggle = True Then
Call OEE_Weekly_Chart
End If
If Fault_Weekly_Toggle = True Then
Call Fault_Weekly_Chart
End If

End Sub

Private Sub UserForm_Activate()
'set the user defined frame live or disable
Set wksdata = Worksheets("DATA STORE")
Set wks_week = Worksheets("OEE Weekly Summary")
Set wks_OEE = Worksheets("OEE History")

If wksdata.Cells(5, 3) = "RECORDING!" Then
OEE_History_frame.Enabled = True
Else
OEE_History_frame.Enabled = False
End If

Fault_Weekly_Toggle = False
OEE_Weekly_Toggle = False
OEE_Period_Toggle = False
Fault_Period_Toggle = False

OEE_date_start_pick.Enabled = False
OEE_date_end_pick.Enabled = False
End Sub

Private Sub UserForm_Initialize()

'set the user defined frame live or disable
Set wksdata = Worksheets("DATA STORE")
Set wks_week = Worksheets("OEE Weekly Summary")
Set wks_OEE = Worksheets("OEE History")

If wksdata.Cells(5, 3) = "RECORDING!" Then
OEE_History_frame.Enabled = True
Else
OEE_History_frame.Enabled = False
End If

Fault_Weekly_Toggle = False
OEE_Weekly_Toggle = False
OEE_Period_Toggle = False
Fault_Period_Toggle = False
OEE_date_start_pick.Enabled = False
OEE_date_end_pick.Enabled = False
End Sub

Private Sub OEE_date_start_pick_Change()
wksdata.Cells(6, 1).Formula = OEE_date_start_pick.Day & "/" & OEE_date_start_pick.Month & "/" & OEE_date_start_pick.Year
wksdata.Cells(6, 2) = ""
MsgBox OEE_date_start_pick.Day
MsgBox OEE_date_start_pick.Month
MsgBox OEE_date_start_pick.Year

OEE_date_end_pick.Enabled = True
OEE_date_end_pick.Format = dtpCustom
OEE_date_end_pick.CustomFormat = Chr(32)
OEE_date_end_pick.MinDate = OEE_date_start_pick.Day & "/" & OEE_date_start_pick.Month & "/" & OEE_date_start_pick.Year
OEE_date_end_pick.MaxDate = wksdata.Cells(5, 2).Value
End Sub
Private Sub OEE_date_end_pick_Change()
wksdata.Cells(6, 2) = OEE_date_end_pick.Day & "/" & OEE_date_end_pick.Month & "/" & OEE_date_end_pick.Year
End Sub
Sub MakeDtpLongDate1()
OEE_date_start_pick.Format = dtpLongDate
Do
w = GetKeyState(1)
DoEvents
Loop While w <> 1 And w <> 0 'wait until left mouse button is released

mouse_event 2, 0, 0, 0, 0   '2 = mouse dwn
mouse_event 4, 0, 0, 0, 0   '4 = mouse up
End Sub
Sub MakeDtpLongDate2()
OEE_date_end_pick.Format = dtpLongDate
Do
w = GetKeyState(1)
DoEvents
Loop While w <> 1 And w <> 0 'wait until left mouse button is released

mouse_event 2, 0, 0, 0, 0   '2 = mouse dwn
mouse_event 4, 0, 0, 0, 0   '4 = mouse up
End Sub
Private Sub OEE_date_start_pick_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
Dim a As Boolean
a = x > (OEE_date_start_pick.Width - 285) 'a = true if mouse is over the grey DTPicker button
If a = False Then Exit Sub
If Button <> 1 Then Exit Sub 'allow only left mouse button
If OEE_date_start_pick.Format <> dtpLongDate Then Call MakeDtpLongDate1
End Sub
Private Sub OEE_date_end_pick_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As stdole.OLE_XPOS_PIXELS, ByVal y As stdole.OLE_YPOS_PIXELS)
Dim a As Boolean
a = x > (OEE_date_end_pick.Width - 285) 'a = true if mouse is over the grey DTPicker button
If a = False Then Exit Sub
If Button <> 1 Then Exit Sub 'allow only left mouse button
If OEE_date_end_pick.Format <> dtpLongDate Then Call MakeDtpLongDate2
End Sub


Any help on this would be most appreciated!!

Thanks in advance

Simon
0
Comment
Question by:simondopickup
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 20278280
Hi simondopickup,

It converting the date to US format. To prevent this, do not send the data as a created string. Simply send the value....

     Private Sub OEE_date_end_pick_Change()
         wksdata.Cells(6, 2) = OEE_date_end_pick.Value
     End Sub

Regards,

Wayne
0
 

Author Comment

by:simondopickup
ID: 20278403
Webtubbs you life saver. Thanks very very much!

Simon
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now