treeview menu item

masoud_sedighy

Registered User.
Local time
Today, 14:56
Joined
Dec 10, 2011
Messages
132
Hello

I need to use tree view menu item sample database from the address (http://www.access-programmers.co.uk/forums/showthread.php?t=170577 )​
Now when (menuid) is more than of 99 for example 105 I receive "error"​
Please help how I can use this database when menuid is more than of 99 , maybe 100000​
Also I do not understand this function specially this line:

-------------------------------
For i = 0 To Len(Trim(intKey)) - 1​
strReturn = strReturn & varHash(Left(Right(intKey, Len(intKey) - i), 1))​
[FONT=&quot] Next
--------------------------------
complete function:

[/FONT]
Private Function NumberToString(intKey As Integer) As String​
On Error GoTo Error_Trap​
Dim i As Integer, strReturn As String​
For i = 0 To Len(Trim(intKey)) - 1​
strReturn = strReturn & varHash(Left(Right(intKey, Len(intKey) - i), 1))​
Next​
NumberToString = strReturn​
Error_Exit:​
Exit Function​
[FONT=&quot] [/FONT]​
Error_Trap:​
MsgBox ("Error Code:" & Err.Number & " Error Description:" & Err.Description)​
Resume Error_Exit​
End Function​
--------------------------------------------
Complete code is like below:
Option Compare Database​
Option Explicit​
Private varHash As Variant​
[FONT=&quot][/FONT]​
Private Sub Form_Load()​
On Error GoTo Error_Trap​
Dim objNode As Node, strKey As String​
Dim rst As DAO.Recordset, intKey As Integer​
varHash = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")​
With TreeView​
.Nodes.Clear​
Set rst = CurrentDb.OpenRecordset("qryMenu")​
If rst.RecordCount > 0 Then​
While Not rst.EOF​
intKey = rst.Fields("MenuID").Value​
If rst.Fields("Parent") = 0 Then​
Set objNode = .Nodes.Add(, , NumberToString(intKey), rst.Fields("Option"))​
objNode.Expanded = True​
Else​
Set objNode = .Nodes.Add(NumberToString(rst.Fields("Parent")), tvwChild, NumberToString(intKey), rst.Fields("Option"))​
End If​
rst.MoveNext​
Wend​
End If​
End With​
rst.Close​
Set rst = Nothing​
[FONT=&quot][/FONT]​
Error_Exit:​
Exit Sub​
[FONT=&quot] [/FONT]​
Error_Trap:​
MsgBox ("Error Code:" & Err.Number & " Error Description:" & Err.Description)​
Resume Error_Exit​
End Sub​
[FONT=&quot] [/FONT]​
Private Sub TreeView_NodeClick(ByVal selectedNode As Object)​
On Error GoTo Error_Trap​
Dim intMenuID As Integer​
Dim strSql, strArg, strForm As String​
intMenuID = StringToNumber(selectedNode.Key)​
strSql = "Select * from tblmenu"​
strSql = strSql & " where menuID=" & intMenuID​
strArg = Nz(CurrentDb.OpenRecordset(strSql).Fields("Action").Value, "")​
strForm = Nz(CurrentDb.OpenRecordset(strSql).Fields("Form").Value, "")​
[FONT=&quot][/FONT]​
Select Case strArg​
Case "Open"​
'DoCmd.OpenForm strForm, acNormal, , , , acWindowNormal​
MsgBox strForm​
Case "Exit"​
Application.Quit​
End Select​
[FONT=&quot][/FONT]​
Error_Exit:​
Exit Sub​
[FONT=&quot] [/FONT]​
Error_Trap:​
MsgBox ("Error Code:" & Err.Number & " Error Description:" & Err.Description)​
Resume Error_Exit​
End Sub​
[FONT=&quot] [/FONT]​
Private Function StringToNumber(strIn As String) As Integer​
On Error GoTo Error_Trap​
Dim i, j As Integer​
Dim strReturn As String​
For i = 0 To Len(Trim(strIn)) - 1​
For j = 0 To UBound(varHash) - 1​
If varHash(j) = Left(Right(strIn, Len(strIn) - i), 1) Then​
strReturn = strReturn & j​
Exit For​
End If​
Next​
Next​
StringToNumber = CInt(strReturn)​
Error_Exit:​
Exit Function​
[FONT=&quot] [/FONT]​
Error_Trap:​
MsgBox ("Error Code:" & Err.Number & " Error Description:" & Err.Description)​
Resume Error_Exit​
End Function​
[FONT=&quot] [/FONT]​
Private Function NumberToString(intKey As Integer) As String​
On Error GoTo Error_Trap​
Dim i As Integer, strReturn As String​
For i = 0 To Len(Trim(intKey)) - 1​
strReturn = strReturn & varHash(Left(Right(intKey, Len(intKey) - i), 1))​
Next​
NumberToString = strReturn​
Error_Exit:​
Exit Function​
[FONT=&quot] [/FONT]​
Error_Trap:​
MsgBox ("Error Code:" & Err.Number & " Error Description:" & Err.Description)​
Resume Error_Exit​
End Function​




 

Users who are viewing this thread

Back
Top Bottom