Link to home
Start Free TrialLog in
Avatar of VK
VKFlag for Germany

asked on

DTPicker doesn't fire change event

Hello Experts.

I'm developing with vb6 (SP3).
I have a DTPicker-Control included in MSCOMCT2.OCX (v.6.00.8418)

placed on a Form.

Code to reproduce behaviour:

Private Sub DTPicker1_Change()
    MsgBox "Date changed !"
End Sub


Private Sub Form_Load()
    DTPicker1.Value = "21.04.1997"
    DTPicker1.Value = "02.02.2000"
End Sub

... but no MsgBox appears !

 
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

It would appear that this event is only fired when the control's value is changed by the control itself and not through code!
Avatar of Ryan Chong
Hi VK,

Try to modify the

Private Sub Form_Load()
   DTPicker1.Value = "21.04.1997"
   DTPicker1.Value = "02.02.2000"
End Sub

to

Private Sub Form_Load()
   DTPicker1.Value = "21/04/1997" 'Or "21-04-1997"
   DTPicker1.Value = "02/02/2000" 'Or "02-02-2000"
End Sub

And try again.

The sub

Private Sub DTPicker1_Change()
   MsgBox "Date changed !"
End Sub

is tested ok.
Hi,

in your Form_load()

change

DTPicker1.Value = "21.04.1997"

to

DTPicker1.Value = CDate("21-04-1997")
Hi,

When you assign vlue to DTPicker change event will not fire. Once you select a date from the DTPicker then it fires change event "DTPicker1_Change"

Onkar
Avatar of VK

ASKER

I know that the event fires when i change the value of the DTPicker from GUI, but i have to do it from code. Calling
Call DTpicker1_Change is not elegant.
Avatar of VK

ASKER

I know that the event fires when i change the value of the DTPicker from GUI, but i have to do it from code. Calling
Call DTpicker1_Change is not elegant.
Avatar of VK

ASKER

I know that the event fires when i change the value of the DTPicker from GUI, but i have to do it from code. Calling
Call DTpicker1_Change is not elegant.
Avatar of VK

ASKER

Thanks for so much reply, but

DTPicker1.Value = CDate("21-04-1997")

AND

DTPicker1.Value = "21/04/1997" 'Or "21-04-1997"
DTPicker1.Value = "02/02/2000" 'Or "02-02-2000"

doesn't work !

It's not a formatting problem i think !

ASKER CERTIFIED SOLUTION
Avatar of nigelrowe
nigelrowe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VK

ASKER

It's not the solution, but it is the best answer describing the reason why.

Ty
VK, sometimes we have to take the inelegant solution when there is no alternative. In this case I think that there is no alternative as the only way I have found to get the change event to fire is by using the GUI control itself. Even the CCRP date time picker control which in some ways is a better control exhibits the same behaviour in respect of the change event when the value is set in code.

I guess you will just have to call the change event in code (or perhaps a nicer solution would be to move the code from the change event to a seperate sub/function and call this directly - and from the change event sub as well).
Avatar of nigelrowe
nigelrowe

Yes, not much of a solution was it? Tim Coffee is right, you don't seem to have much of a choice here. Cheers and good luck.
one lump of sugar or two Tim Coffee?
Two please and a shot of Irish Whiskey as well thanks Azra!
Avatar of VK

ASKER

Ty TimCottee and AzraSound for the good resonance. Next time if i'm unsure whom to give the points Tim would get them :-).

Cu