Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date picker returning strange values!

Posted on 2007-11-13
2
Medium Priority
?
457 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

636 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