Hello,
I have created a menu in VB.Net which creates several button dynamically. Each of these buttons opens the same form, but I would like to pass through a unique number depending on which button is chosen. At the minute my menu is created but only the last button opens the form - instead of all the buttons. Any ideas where I am going wrong???
Here is some relevant code:-
While sqlDtr.Read
.
.
cmdButton = Me.MakeANewButton(toolBar,
CStr(sqlDtr("Caption")), CInt(sqlDtr("Group")), CInt(sqlDtr("ParentId")), nextInt, AddressOf btnSearch_Click)
.
.
nextInt = nextInt + 1
End While
sqlDtr.Close()
Function MakeANewButton(ByVal commandBar As Office.CommandBar, ByVal caption As String, ByVal GroupId As Integer, ByVal ParentID As Integer, ByVal faceID As Integer, ByVal clickHandler As Office._CommandBarButtonEv
ents_Click
EventHandl
er) As Office.CommandBarButton
Try
newButton = CType(commandBar.Controls.
Add(Office
.MsoContro
lType.msoC
ontrolButt
on), Office.CommandBarButton)
newButton.Style = Office.MsoButtonStyle.msoB
uttonCapti
on
newButton.Caption = caption
newButton.FaceId = faceID
AddHandler newButton.Click, clickHandler
If Begin_Group = -1 Then
Begin_Group = 0
newButton.BeginGroup = True
Else
newButton.BeginGroup = False
End If
newButton.DescriptionText = CStr(GroupId)
Return newButton
Catch ex As System.Exception
' Add code here to handle the exception.
MsgBox(ex.Message)
Return Nothing
End Try
End Function
Private Sub btnSearch_Click(ByVal barButton As Office.CommandBarButton, ByRef someBool As Boolean)
Try
If Not IsNothing(frmFind) Then
If Not frmFind.IsDisposed Then
frmFind.BringToFront()
Else
frmFind = New frmSearch()
End If
Else
frmFind = New frmSearch()
End If
frmFind.ShowDialog()
Catch ex As Exception
MsgBox(ex.Message)
Finally
frmFind = Nothing
End Try
End Sub
Thanks,
mcdermon
Start Free Trial