Link to home
Start Free TrialLog in
Avatar of ExtremeFitness
ExtremeFitness

asked on

VB 6.0 raising the event closeup

I am trying to close the calendar view on the DTPicker obejct once the desired date has been achived.

How can I do this?
Avatar of mvidas
mvidas
Flag of United States of America image

Hi ExtremeFitness,

Can you explain a little more what you mean? The _CloseUp event is fired when a date is chosen on the calendar view, and only the chosen date should remain in the calendar view. I guess I should ask what you mean by "desired date has been achieved"?

Matt
Avatar of ExtremeFitness
ExtremeFitness

ASKER

mvidas,
When the user clicks on the month change, I check to see if 4 months were added to the original date.  Once this happens, I wish to close the calendar view.
EF
EF,

I understand now, sorry about that wasn't quite sure.

I've tried a variety of ways of doing this in the past, and the final method really depends on what you want to be left after closing the calendar mode.

Do you want the original date returned as the value? If so, then use SendKeys with escape:

Dim DTInitVal As Variant

Private Sub DTPicker1_DropDown()
 DTInitVal = DTPicker1.Value
End Sub

Private Sub DTPicker1_Change()
 If DateAdd("m", 4, DateSerial(Year(DTInitVal), Month(DTInitVal), 1)) <= _
  DTPicker1.Value Then SendKeys "{ESC}"
End Sub


However, if you want the "original date + 4 months" as the value, make .visible=false then .visible=true:

Private Sub DTPicker1_Change()
 If DateAdd("m", 4, DateSerial(Year(DTInitVal), Month(DTInitVal), 1)) <= _
   DTPicker1.Value Then
  DTPicker1.Visible = False
  DTPicker1.Visible = True
 End If
End Sub

Matt
Matt,
I have no issue figuring out the datediff, it is 'minimizing' the calendar of the object.
I have tried the SendKeys, but did not work.
Avri
My code
If DateDiff("m", dtStart, dtpExpireDate) > 4 Then
           
           
            MsgBox "Maximum of 4 Month Time Credit Allowed", vbInformation
            dtpExpireDate.value = DateAdd("m", 4, dtStart)
            dtpExpireDate.Refresh
           
            btnSave.Enabled = DateDiff("m", dtStart, dtpExpireDate) > 0
            SendKeys "{ESC}"
 
            DoEvents
            Exit Sub
    End If

ASKER CERTIFIED SOLUTION
Avatar of mvidas
mvidas
Flag of United States of America image

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
Matt,
Sorry, no dice....
I event placed a doevents in betweens

             dtpExpireDate.Value = DateAdd("m", 4, dtStart)
            dtpExpireDate.Visible = False
            doevents
            dtpExpireDate.Visible = True
            doevents

Thanks about the enabling of the btnSave, done that twice.
Avri
Hi Avri,

Strange, that worked for me (though it was just a simple form with a DTPicker named dtpExpireDate and the button, I still just copied/pasted from dtpExpireDate_Change in the form's module). Just a thought, maybe you could try repainting the form?

            dtpExpireDate.Value = DateAdd("m", 4, dtStart)
            dtpExpireDate.Visible = False
            dtpExpireDate.Visible = True
            Me.Repaint

If not, I'm not sure what else I could suggest..
Matt
can you do

Me.SetFocus
DTPicker1.SetFocus
I'm done... decided to ignore the issue.  
The software will retire in five months.