Solved

mnuItems at runtime

Posted on 1998-12-14
6
274 Views
Last Modified: 2010-05-03
Is there a way to add menu items to a menu at runtime?
0
Comment
Question by:gwu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Accepted Solution

by:
polygon earned 50 total points
ID: 1450057
Yes,
create a menu array. If you know what items will be added, you may simply create them hidden and show them when needed.
If you don't know what will the items be, like when creating Recent Files list, you will need a menu array. It is created by adding same name for several items and different indeces.

Also, if you do know how much your items will be, but don't know what will they contain, you nay again just create them, set them to hidden and change them before you need to shoe 'em.
0
 

Author Comment

by:gwu
ID: 1450058
I can see that creating a menu array could work, but if I want to add new menu Items at runtime, I don't see a way to do that given the methods and properties available.
0
 
LVL 3

Expert Comment

by:jjmartin
ID: 1450059
Here is some code for you, this adds menu items dynamically during load from a database.

On Error GoTo ErrHandler

    Dim strNameFile As String
    Dim strName As String
   
    Dim dbsNames As Database
    Dim rstNames As Recordset
   
    Dim intRet As Integer
    Dim i As Integer
       
    strNameFile = strNetworkDB
   
    Set dbsNames = OpenDatabase(strNameFile)
    Set rstNames = dbsNames.OpenRecordset("tblNames")
   
    Name_Idx = 0
    Do Until rstNames.EOF
        If Name_Idx > 0 Then
            Load Me.mnuFileOpenName(Name_Idx)
        End If
        Me.mnuFileOpenName(Name_Idx).Caption =         rstNames!Name
        Name_Idx = Name_Idx + 1
        rstNames.MoveNext
    Loop
   
    mnuFileOpenNetwork.Enabled = True
    mnuFileSaveNetwork.Enabled = True
   
    Exit Sub


0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 3

Expert Comment

by:jjmartin
ID: 1450060
ignore:
     mnuFileOpenNetwork.Enabled = True
     mnuFileSaveNetwork.Enabled = True
those are something specific to my project.
0
 

Expert Comment

by:deal051298
ID: 1450061
I saw this and have done:

Private Sub mnuViewSort_Click()
Dim RS As Recordset
Dim i As Integer

Set RS = DB.OpenRecordset("Routenametable", dbOpenSnapshot)

Me.mnuDynRoutes(0).Visible = True

i = 0

While Not RS.EOF
    i = i + 1
    Load Me.mnuDynRoutes(i)
    Me.mnuDynRoutes(i).Caption = RS!Name
    RS.MoveNext
Wend

If i > 0 Then Me.mnuDynRoutes(0).Visible = False

RS.Close

End Sub

I'm using the first (0) menu item as a "No items here" tag
0
 

Expert Comment

by:deal051298
ID: 1450062
Oh yeah, I had to create at least one mnu item (Hence the 0 index) at design time to kick off the array. and I used this to clear them:

For Each m In mnuDynRoutes
    If m.Index <> 0 Then Unload m
Next m

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question