Passing textbox value to string variable

P

Pinacle

I have the following code under textbox_Afterupdate event

Dim newstr As Integer
newstr = Left(Me.Req_.Text, 2)

The above code is reading the value (Me.Req_.Text , Ex:'1423S') from the
form....but when i debug it the value in 'newstr' is 0. Could someone please
help !

Thanks
 
B

Beetle

You're naming your variable as if it were a string, but you're
declaring it as an integer, then trying to pass a string value
to it.

Either declare the variable as a string, or if the variable
needs to be an integer, convert the value before you pass it;

CInt(Left(Me.Req, 2))
 
H

Hans Up

Pinacle said:
I have the following code under textbox_Afterupdate event

Dim newstr As Integer
newstr = Left(Me.Req_.Text, 2)

The above code is reading the value (Me.Req_.Text , Ex:'1423S') from the
form....but when i debug it the value in 'newstr' is 0. Could someone please
help !

Thanks

What is the data type of Left(Me.Req_.Text, 2)?

Debug.Print TypeName(Left(Me.Req_.Text, 2))

If "String", you could try:

newstr = CInt(Left(Me.Req_.Text, 2))
 
P

Pinacle

Thank you Beetle and Hans up !! i converted the string value into integer and
it worked perfect !!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top