MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Anyway to trigger a macro when user tab or mouse in to a textbox

  Asked By: Frankie    Date: Jan 19    Category: MS Office    Views: 727

I'm trying to have a calendar control popup when a user tab or mouse
click a textbox. What is the vba code to do this? I've gotten as far
as creating the calendar control on a separate forms so that it can
popup but I'm having trouble triggering it.



3 Answers Found

Answer #1    Answered By: Vidhya Iyer     Answered On: Jan 19

In the vba  window (or form design window) right-click on the textbox  and
select "View Code"
the right-upper pull-down probably is at the "change" event.
Pull down to the MouseMove event.
It will create a new event.

For a textbox called "machno" I created:
Private Sub Machno_MouseMove(ByVal Button As Integer, ByVal Shift As Integer,
ByVal X As Single, ByVal Y As Single)
Application.StatusBar = "X = " & X & ", Y = " & Y
End Sub

Which continually updates the Status bar with the X and Y position of the mouse.

Be careful, this continually calles the macro  while the mouse  is in motion!
if you do much with this macro, it may become unwieldy!

Answer #2    Answered By: Cyka Jansen     Answered On: Jan 19

Ah.. just re-read this posting... you don't want it to activate when you move
OVER the box, but when you click INTO the box,

Try using the "Enter" event. executes when the box is "entered" either by mouse
or tab.

Answer #3    Answered By: Robin Hayes     Answered On: Jan 19

I'll have to update that with the mouse  control. I've just
let user  press 'd' to activate the Calendar.

Now I have another problem.
I'm calling frmCalendar.Show when the user enters the box and
press 'd', that will popup  the calendar  GUI... When I select the
date, it loads the date in to the textbox  and gives out an Run-time
error 400 Form already displayed; can't show modally.

There is two form. frmCalendar, frmVA. The frmVA is the main form
with all the textboxes. frmCalendar is the calendar popup.

Some snipet from the code  on frmVA:

Private Sub txtReferralDate_Change()
End Sub

Private Sub txtDOB_Change()
End Sub

Some snipet from the code on frmCalendar:
Private Sub Calendar1_Click()
If frmVA.txtReferralDate.Value = "d" Then
frmVA.txtReferralDate.Value = Calendar1.Value
End If

If frmVA.txtDOB.Value = "d" Then
frmVA.txtDOB.Value = Calendar1.Value
End If

Unload Me
End Sub