Right Function

shamas21

Registered User.
Local time
Today, 17:49
Joined
May 27, 2008
Messages
162
Hi All

It wont give me the RIGHT() Function for my variable ‘r’.

Please cope and paste the code and you will see.

Any help appreciated

Thanks


Code:
Sub mac1()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim r As String
    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.Open "G:\Knowledge\EndUser.mdb"
    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
    'Output the list of all users in the current database.
    Debug.Print rs.Fields(0).Name
    While Not rs.EOF
        r = rs.Fields(0).Value
        rs.MoveNext
    Wend
    MsgBox r
    MsgBox Right(r, 4)
    
End Sub
 
if you put the msgbox Inside the loop it will work "r" does not have a value outside the loop therefore you cannot extract the last 4 characters of an empty string.

CodeMaster::cool:
 
I had assumed that Msgbox r had produced a value, namely the last of the loop, however as the code Msgbox Right(r, 4) should work I cannot add anything useful, just remain puzzled.

Brian
 
Agree with all of the above, but just throwing this out there ... not sure if it is an issue or could cause one or not in this situation.

r is declared as a string, but what if the first field is a long number (assuming the first field is an ID autonumber)? Would that jack the Right function up so bad it would display nothing?

-dK
 
Agree with all of the above, but just throwing this out there ... not sure if it is an issue or could cause one or not in this situation.

r is declared as a string, but what if the first field is a long number (assuming the first field is an ID autonumber)? Would that jack the Right function up so bad it would display nothing?

-dK

the variable r contains 'WRKCHISWELZ5504'

all i want is the last 4 digits '5504'

msgbox r displays 'WRKCHISWELZ5504'
however, msgbox Right(r,4) displays nothing i.e. blank

I cant work it out!!!
 
Just for grins ... set r type to variant and see if that changes anything. Probably not, but just as a check.

-dk
 
Perhaps you are suffering from a reference problem. This happens occasionally. If you have a DAO reference set, try unchecking it and closing and then reopening and you might have to check it again manually.
 
Perhaps you are suffering from a reference problem. This happens occasionally. If you have a DAO reference set, try unchecking it and closing and then reopening and you might have to check it again manually.

That happens to the Left, Mid, Right functions occasionally, so that is why I suggested this.
 
I have tested your code on my machine and everything works as expected so I believe that Bob has given you the correct explanation.
 
I have tested your code on my machine and everything works as expected so I believe that Bob has given you the correct explanation.

Thanks guys. All works fine.

Bob you a genious
 

Users who are viewing this thread

Back
Top Bottom