Calendar control and KeyDown/KeyPress event

Does anyone know what are the KeyDown or KeyPress parameters for ActiveX calendar control? I've need to requery subform when user moves day selector with keyboard arrow keys.

Now user can select the day with mouse click, but it would be nice he/she could browse "diary" backward and forward using arrow keys.

I've already tried:

Private Sub XCalendar_KeyDown(KeyCode As Integer, Shift As Integer)

and ...

Private Sub XCalendar_KeyPress(KeyAscii As Integer)

but Access gives me error that given parameters are not right.

I would appreciate your help!

Paasky
LVL 10
paaskyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrianWrenCommented:
The key press and down parameters are identical to the same events for Access intrinsic controls.

KeyCode As Integer, Shift As Integer for KeyDown,
KeyAscii As Integer for KeyPress

If you set KeyCode = 0 in the KeyDow event, the keystroke essentiall never happened.

If the shift key is down, Shift = 1, if the control key, 2.  If the alt key, 4.

They are summed.  All three = 7.

CHR$(KeyCode) is the character pressed, and you can test for cursor keys' values, too.

   Left  = 37
   Right = 39
   Up    = 38
   Down  = 40

Brian
0
paaskyAuthor Commented:
Brian,

I guess ActiveX control's make exception for that rule every parameter are same for all controls... :(

When looking at Calendar objects Event properties there are only five available (visible) events: OnUpdate (which never occurs!), GotFocus, LostFocus, OnExit and OnEnter. However it has also OnClick event, but you have to write that yourself:

Private Sub xCalendar_Click()
    Me.subform1.Requery
End Sub


I also tried place the code on Form's KeyDown event, but seems that when ActiveX control has focus the form is not responding to keyevents.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If Me.ActiveControl.Name = "XCalendar" Then
        If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Or KeyCode = vbKeyLeft Or KeyCode = vbKeyRight Then
            Me.Subform1.Requery        End If
    End If
End Sub

Paasky

0
paaskyAuthor Commented:
Adjusted points to 125
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

BrianWrenCommented:
Go to the module design window of the form.  At the top, there is a dropdown where you can select the objects on the form.  Select the control.  To the right is a list of events.  KeyDown, and KeyPress are there.  Select one of them form the list, and Access will build the framework of the event, with the focus in the sub.  Put your code there, and the event will trigger as billed, 'Down,' or 'Press.'

Brian
0
paaskyAuthor Commented:
I've never tried looking events there... This is good thing to know.

I made event triggers like you suggested but somehow they seem not fire when I hit cursor keys (other key press is registered):

Private Sub XCalendar_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
    ' Occurs when user presses for eg. 'A'...
    Debug.Print "KeyDown"
End Sub

Private Sub XCalendar_KeyPress(KeyAscii As Integer)
    Debug.Print "KeyPress"
End Sub

Maybe there's needed some other way to catch value change?

Btw, my XCalendar is not bound to table field - it's just for filtering.

Paasky
0
BrianWrenCommented:
Turn the form's keypreview on, (or off, depending on it's current state).

Be sure to remove the keypress/down for the form which you said you had added.

Brian
0
paaskyAuthor Commented:
Okay, I tried removing Form's KeyEvents and changed keypreview from Yes to No.. but it's still not working.

Any other suggestions?

Paasky
0
BrianWrenCommented:
Boy!  You're right, those events don't take place!

But the After Update does.  You should be able to use that in association with the value of the control after the update to get the functionality you are after.

Brian
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
paaskyAuthor Commented:
Good idea, I will try After Update on Monday...

Calendar control seems to work strange in many other ways too: If I try to set its "default" value to current day in form's OnOpen event, it doesn't work. So I've to user timer to refresh the value after 50 milliseconds... And the control corrupts someway - there seems to be two same day next each other... then I use refresh to fix the  situation and after that it changes FirstDay from Monday to Sunday... very strange indeed.

Anyway it's "free" ActiveX so better not complain too much. I wonder what happened to OutLine control which was included with MS Access 2.0 DK..?

Regards,
Paasky

0
paaskyAuthor Commented:
Couldn't wait til Monday... I just get to my office and tested AfterUpdate with Calendar... and it works!

Thank you very much Brian. Glad there was a work around for this problem.

Best regards,
Paasky
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.