len function always returns 2

mary.h

Registered User.
Local time
Today, 18:30
Joined
Aug 21, 2003
Messages
48
Hello,

I am desperate, as this keeps me now for more then 3 hours.
I run a switchboard which shows different items depending on the users login i.e. rights. That's why the "back"-Button cannot be fixed with one value for all users, but needs to be dynamic. Therefore I've written this code:

Code:
Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.

    ' Constants for the commands that can be executed.
    Const conCmdGotoSwitchboard = 1
    Const conCmdOpenFormAdd = 2
    Const conCmdOpenFormBrowse = 3
    Const conCmdOpenReport = 4
    Const conCmdCustomizeSwitchboard = 5
    Const conCmdExitApplication = 6
    Const conCmdRunMacro = 7
    Const conCmdRunCode = 8
    Const conCmdOpenPage = 9
    Const conCmdReturnToSwitchboard = 10

    ' An error that is special cased.
    Const conErrDoCmdCancelled = 2501
    
    Dim con As Object
    Dim rs As Object
    Dim stSql As String
    Dim strFormerSwitchboard As String, lngLänge As Long
    
'On Error GoTo HandleButtonClick_Err

...    

    Select Case rs![Command]
        
        ' Go to another switchboard.
        Case conCmdGotoSwitchboard
            strSwitchboards = strSwitchboards & CStr(Me.SwitchboardID)
            Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & rs![Argument]
            
...
            
        ' Go back one step
        Case conCmdReturnToSwitchboard
            strFormerSwitchboard = Right(strSwitchboards, 1)
            Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & strFormerSwitchboard
           Left(strSwitchboards, len(strSwitchboards) -1)
        
    
    End Select

...

End Function


But the len-function always returns 2, even the strSwitchboards is "1234".

Who can help?

Thank you so much in advance.
Mary H.
 
Last edited by a moderator:
Is something missing from the code listing here?
Code:
        Case conCmdReturnToSwitchboard
            strFormerSwitchboard = Right(strSwitchboards, 1)
            Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & strFormerSwitchboard
           Left(strSwitchboards, len(strSwitchboards) -1)
If Access has compiled this code, the len function would've been capitalized, but that's the minor issue.

Left(strSwitchboards, len(strSwitchboards) -1
doesn't look like it gets assigned to anything.

Have you tried compiling the code?
 
I don't see where strSwitchboards is defined. If it is defined as an integer, its length would always be 2. I think your problem is attempting to use string functions on numeric variables. Number datatypes are NOT strings.
 
Hi,

1. strSwitchboards is defined as string in the Declaration part of the module. But what I do is adding a number (me.SwitchboardID) to the string, as the string shall be the map of the menus the user has gone. So "123" stands for: started at SwitchboardID 1, then went to 2 and then to 3.
But when I debug.print the string strSwitchboards it prints "123".

2. the correct the code part is:
' Go back one step
Case conCmdReturnToSwitchboard
strFormerSwitchboard = Right(strSwitchboards, 1)
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" & strFormerSwitchboard
strSwitchboards = Left(strSwitchboards, len(strSwitchboards) -1)

What it does is, if I have the string "123" and the back button is pressed, it takes the last "digit" as the former switchboard and goes there, then it sets the string back to "12". So if back button is pressed again, The former is 2 and so on.

So I guess it has indeed something to do with the fact, that I add a number to a string, even this part does not give the error. How can I overcome the problem by still having what I want???

Many thanks in advance.
Mary
 
Sorry sorry sorry

Sorry to all who have given time to my question.

It was all my fault. I doublechecked and indeed instead of defining strswitchboards as string, it was an integer.

So much shame on me. I feel really bad.

The guilty Mary.
 

Users who are viewing this thread

Back
Top Bottom