Results 1 to 3 of 3
  1. #1
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47

    Convert string to integer

    I am writing the following code but It doesn't convert string to integer and gives me overflow message. The struse will store string in the following format:


    1. first character A
    2. next characters numbers.

    Code:
    Private Sub Command0_Click()
    Dim StrUser As String
    Dim StrUser1 As String
    Dim Intuser As Integer
    StrUser = Environ("username")
    StrUser1 = Right(StrUser, Len(StrUser) - 1)
    Intuser = Val(StrUser1)
    MsgBox StrUser1
    MsgBox Intuser
    End Sub
    Any help will be much appreciated. Thanks

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    integers can only go up to 32767. If your number is bigger than that, you will get the overflow error. Try changing intUser to long

    also, a slight more efficient way of getting your number is

    mid(StrUser,2)

  3. #3
    AmanKaur123 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2017
    Posts
    47
    Thanks it worked

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Convert String to Date in Web App
    By carlo76 in forum SharePoint
    Replies: 3
    Last Post: 03-06-2015, 11:05 AM
  2. Convert rows into string
    By KPABA in forum Queries
    Replies: 1
    Last Post: 06-06-2013, 06:03 PM
  3. How to Convert string to Number?
    By taimysho0 in forum Programming
    Replies: 1
    Last Post: 02-24-2012, 01:57 PM
  4. Adding column as INTEGER makes it a long integer?
    By luckycharms in forum Programming
    Replies: 2
    Last Post: 10-20-2010, 02:47 PM
  5. Convert string to date
    By ~SwAmPdOnKeY~ in forum Queries
    Replies: 4
    Last Post: 09-11-2008, 07:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums