Group:  Microsoft Word ยป microsoft.public.word.vba.userforms
Thread: Finding name of subroutine or button (probably simple)

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Finding name of subroutine or button (probably simple)
"Gary" <gary167[ at ]yahoo.com> 22.09.2006 16:49:31
I have a userform setup with a multipage control. I have various
textboxes that need to be filled out for various information. I have
also included a option button (copyhpm2) which will allow me to do a
quick subroutine and then allow me to update the text of a box.

My issue is that I would like to be able to find out which button has
been pushed. (I know I could hardcode this with a variable, but there
are a lot of these).


As another footnote, how can I determine the next, or previous, text
box in the tab order programatically.


Thanks,


Gary

Re: Finding name of subroutine or button (probably simple)
"Jean-Guy Marcil" <NoSpam[ at ]LeaveMeAlone> 23.09.2006 18:34:44
Gary was telling us:
Gary nous racontait que :

[Quoted Text]
> I have a userform setup with a multipage control. I have various
> textboxes that need to be filled out for various information. I have
> also included a option button (copyhpm2) which will allow me to do a
> quick subroutine and then allow me to update the text of a box.
>
> My issue is that I would like to be able to find out which button has
> been pushed. (I know I could hardcode this with a variable, but there
> are a lot of these).
>
>
> As another footnote, how can I determine the next, or previous, text
> box in the tab order programatically.

Try these:

'_______________________________________
Private Sub CommandButton1_Click()

MsgBox "My name is """ & Me.ActiveControl.Name & """."

End Sub
'_______________________________________

'_______________________________________
Private Sub TextBox2_Change()

Dim lngTabID As Long
Dim lngTabIDNext As Long
Dim strControlName As String
Dim ctrlTab As Control

lngTabID = Me.ActiveControl.TabIndex
lngTabIDNext = 0

For Each ctrlTab In Me.Controls
If TypeOf ctrlTab Is TextBox Then
With ctrlTab
If .TabIndex > lngTabID Then
If lngTabIDNext = 0 Then
lngTabIDNext = .TabIndex
strControlName = .Name
ElseIf .TabIndex < lngTabIDNext Then
lngTabIDNext = .TabIndex
strControlName = .Name
End If
End If
End With
End If

Next

If strControlName <> "" Then
MsgBox "The next textbox in the tab order is """ _
& strControlName & """."
Else
MsgBox "This is the last textbox in the tab order."
End If

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Re: Finding name of subroutine or button (probably simple)
"Gary" <gary167[ at ]yahoo.com> 30.09.2006 05:20:01
Sorry for late reply. Had a half-dozen other projects creep up on me!

I'll have to work this one out line by line.

Thanks,
Gary
Jean-Guy Marcil wrote:
[Quoted Text]
> Gary was telling us:
> Gary nous racontait que :
>
> > I have a userform setup with a multipage control. I have various
> > textboxes that need to be filled out for various information. I have
> > also included a option button (copyhpm2) which will allow me to do a
> > quick subroutine and then allow me to update the text of a box.
> >
> > My issue is that I would like to be able to find out which button has
> > been pushed. (I know I could hardcode this with a variable, but there
> > are a lot of these).
> >
> >
> > As another footnote, how can I determine the next, or previous, text
> > box in the tab order programatically.
>
> Try these:
>
> '_______________________________________
> Private Sub CommandButton1_Click()
>
> MsgBox "My name is """ & Me.ActiveControl.Name & """."
>
> End Sub
> '_______________________________________
>
> '_______________________________________
> Private Sub TextBox2_Change()
>
> Dim lngTabID As Long
> Dim lngTabIDNext As Long
> Dim strControlName As String
> Dim ctrlTab As Control
>
> lngTabID = Me.ActiveControl.TabIndex
> lngTabIDNext = 0
>
> For Each ctrlTab In Me.Controls
> If TypeOf ctrlTab Is TextBox Then
> With ctrlTab
> If .TabIndex > lngTabID Then
> If lngTabIDNext = 0 Then
> lngTabIDNext = .TabIndex
> strControlName = .Name
> ElseIf .TabIndex < lngTabIDNext Then
> lngTabIDNext = .TabIndex
> strControlName = .Name
> End If
> End If
> End With
> End If
>
> Next
>
> If strControlName <> "" Then
> MsgBox "The next textbox in the tab order is """ _
> & strControlName & """."
> Else
> MsgBox "This is the last textbox in the tab order."
> End If
>
> End Sub
> '_______________________________________
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE[ at ]CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net