
October 18th, 2012, 01:06 AM
|
|
|
I am still not sure what you are trying to do, but I assume that you want to programmatically add items to a menu. This is usually accomplished using an object array. In the example below, I allow the user to enter a new mailbox name. The first level menu is preloaded, and the first menu item of second level is preloaded into a menu array. The routine then copies the structure of a table to a new table using the new name. A new member of the object array is loaded, and the new name assigned to the caption. The new name and it's index is then stored in the Registry to be loaded automatically the next time the program is loaded. Each menu item has a common name and an associated index. There is a common click event containing the index value:
Private Sub mnuBox_Click(index As Integer)
J.A. Coutts
Code:
Private Sub mnuNew_Click()
Dim N%
Dim strTemp As String
strTemp = InputBox("Enter Name of Mailbox:")
If Len(strTemp) = 0 Then
Exit Sub
Else
'Check if table already exists
On Error GoTo Continue
adoConn1.Execute ("SELECT * FROM " & strTemp & " WHERE 0 = 1;")
MsgBox strTemp & " already exists!", vbExclamation
Exit Sub
End If
Continue: 'Table does not exist yet
On Error GoTo mnuNewErr
adoConn1.Execute ("SELECT * INTO " & strTemp & " FROM Dummy WHERE 0 = 1;")
'If we get this far, the table was sucessfully created
'Add to menu
N% = mnuBox.Count
Load mnuBox(N%)
mnuBox(N%).Caption = strTemp
'Add to registry
Call SaveSettings("Mailbox" & CStr(N%), strTemp)
Exit Sub
mnuNewErr:
MsgBox "Error " & CStr(err) & ": " & Error$(err)
End Sub
|