Solved

Date picker returning strange values!

Posted on 2007-11-13
2
417 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

20 Experts available now in Live!

Get 1:1 Help Now