Results 1 to 15 of 15
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Overload On Long Variable

    Hi Guys, i have tried a couple of things to fix this one



    I have 16 lists on screen, each list represents a route number,

    I have tried setting variables as Integer knowing the variables are whole numbers, then converting to Long using Clng(), i was receiving runtime error 6 overload which is normally an incorrect variable setting and after multiplying the TWIPS there is a result of 1404246 in the immediate window, still receive an overload (Now Set to Long) to accommodate large numbers that may calculate to include decimals.

    Is there a better way of doing this ?

    So my intention is because there 16 list boxes, i want the option to expand the top row of lists to display without having to scroll on each list


    Once I know the best method, i can expand/collapse a row of lists at a time.


    Code:
    Const TWIPS_PER_CM As Long = 283
    Dim intMainIndex As Integer, intIndex As Integer
    
    Dim lngOrgSize As Long, lngLarge As Long
    
    
    Dim strPath As String, strFile As String
    
    
    intMainIndex = Me.tbcMainMenu.Value ' Tab Page Index
    intIndex = Me.cboOption7.ListIndex 'Combo Index
    lngLarge = 4962
    lngOrgSize = 2210
    
    
    Select Case intMainIndex
    Case Is = 2 'VIEW ROUTES
        Select Case intIndex
        Case Is = 0 ' LISTS 1,5,9,13
        
            With Me.lstRoute1        
    Debug.Print lngLarge * TWIPS_PER_CM
            
            Stop
    
    
    
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
            With Me.lstRoute5
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
            With Me.lstRoute9
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
            With Me.lstRoute13
                .Height = (lngLarge * TWIPS_PER_CM)
            End With
        
        Case Is = 4 'REST TO ORIGIONAL SIZE
            With Me.lstRoute1
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            With Me.lstRoute5
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            With Me.lstRoute9
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            With Me.lstRoute13
                .Height = (lngOrgSize * TWIPS_PER_CM)
            End With
            
        End Select
    End Select

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    Why have a nested Select block when it only has one case? Your issue isn't obvious (at least to me). 4692*283 does not exceed the size of a long variable, so I don't see a problem there. Knowing which line raises the error might help. This may be something that you need to upload a db in order to solve it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Try setting lngLarge and lngOrgSize to CM instead of twips.
    Why is code choosing third tab page, but modifying the first page?

    Edit: Everyone is seeing this wrong. Overflow is not due to the calculation, it's because the code is trying to set the listbox height to a bit over 81 FEET.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    4692*283 = 1,327,836
    That still gives me error 6?

    Code:
    Sub TestLong()
    Dim lngResult As Long
    Dim i1 As Integer, i2 As Integer
    i1 = 4692
    i2 = 283
    lngResult = i1 * i2 'Errors here
    Debug.Print lngResult
    
    
    End Sub
    yet Long is supposed to be able to contain -2,147,483,648 to 2,147,483,648

    If I use
    lngResult = 2147483640, it accepts it no problem?

    This works
    Code:
    Sub TestLong()
    Dim lngResult As Long
    Dim i1 As Long, i2 As Long
    i1 = 4692
    i2 = 283
    lngResult = i1 * i2
    Debug.Print lngResult
    
    
    End Sub
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    I asked on another site about this and the answer I received was
    Multiply an integer by an integer results in an integer value
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Thanks guys, i have this working by avoiding Const to Twips and using Long variables

    Code:
    Dim lngOrg As Long, lngLarge As Long
    lngOrg = 2210
    lngLarge = 4962
    
    
    Dim strPath As String, strFile As String
    
    
    intMainIndex = Me.tbcMainMenu.Value ' Tab Page Index
    intIndex = Me.cboOption7.ListIndex 'Combo Index
    
    
    Select Case intMainIndex
    Case Is = 2 'VIEW ROUTES
        Select Case intIndex
        Case Is = 0 ' LISTS 1,5,9,13
        
            With Me.lstRoute1
                .Height = lngLarge
            End With
            With Me.lstRoute5
                .Height = lngLarge
            End With
            With Me.lstRoute9
                .Height = lngLarge
            End With
            With Me.lstRoute13
                .Height = lngLarge
            End With
        Case Is = 1
            'Lists 2,6,10,14
        Case Is = 2
            'Lists 3,7,11,15
        Case Is = 3
            'Lists 4,7,12,16
            
        Case Is = 4 'REST TO ORGIGIONAL SIZE
            With Me.lstRoute1
                .Height = lngOrg
            End With
            With Me.lstRoute5
                .Height = lngOrg
            End With
            With Me.lstRoute9
                .Height = lngOrg
            End With
            With Me.lstRoute13
                .Height = lngOrg
            End With
            
        End Select
    End Select

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    FWIW I was consequently advised that only one of the values needs to be Long.
    However someone mentioned variants, and one of the integers as a variant works as well.

    @DMT Dave,
    I would save some typing and just use With Me, then
    Code:
     .lstRoute1.Height = lngOrg
     .lstRoute5.Height = lngOrg
     .lstRoute9.Height = lngOrg
     .lstRoute13.Height = lngOrg
    
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Thanks for the tip WGM, So With Me, didn't realize you could declare an array with nothing after ("ME")

    This is why you guys are the GOAT in vba

    Just adapted and yes, it does shorten the procedure

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    Dave,
    It is just an object, and you specify the properties by starting them with a full stop .
    The form is an object, the control is an object.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    if you want to save more typing, you don't need Is for =

    Case Is = 2

    you can just use

    Case 2

    you use Is when you want something like

    Case Is <=2


    as with text - you wouldn't use Like unless you are using a wild card

    A Like "abc"

    is the same as

    A = "abc"

  11. #11
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Ah ok CJ, thank you, yes can see what you mean, this is now what i have based on suggestions, so not only my overload issue, now cleaned up

    The combo has 4 options
    case 0 is expand top line of lists
    case 1 is next row of lists
    etc....
    case 4 is reset all lists height and top

    added top on bottom row

    Code:
    Dim lngOrg As Long, lngLarge As Long, lngOrgH As Long, lngNewH As Long
    lngOrg = 2210
    lngLarge = 4962
    lngOrgH = 11291
    lngNewH = 8558
    
    
    Dim strPath As String, strFile As String
    
    
    intMainIndex = Me.tbcMainMenu.Value ' Tab Page Index
    intIndex = Me.cboOption7.ListIndex 'Combo Index
    
    
    Select Case intMainIndex
    Case 2 'VIEW ROUTES
        Select Case intIndex
        Case 0 ' LISTS 1,5,9,13
            With Me
            .lstRoute1.Height = lngLarge
            .lstRoute5.Height = lngLarge
            .lstRoute9.Height = lngLarge
            .lstRoute13.Height = lngLarge
            .lstRoute2.Height = lngOrg
            .lstRoute6.Height = lngOrg
            .lstRoute10.Height = lngOrg
            .lstRoute14.Height = lngOrg
            .lstRoute3.Height = lngOrg
            .lstRoute7.Height = lngOrg
            .lstRoute11.Height = lngOrg
            .lstRoute15.Height = lngOrg
            .lstRoute4.Height = lngOrg
            .lstRoute8.Height = lngOrg
            .lstRoute12.Height = lngOrg
            .lstRoute16.Height = lngOrg
            End With
       Case 1
            With Me
            .lstRoute1.Height = lngOrg
            .lstRoute5.Height = lngOrg
            .lstRoute9.Height = lngOrg
            .lstRoute13.Height = lngOrg
            .lstRoute2.Height = lngLarge
            .lstRoute6.Height = lngLarge
            .lstRoute10.Height = lngLarge
            .lstRoute14.Height = lngLarge
            .lstRoute3.Height = lngOrg
            .lstRoute7.Height = lngOrg
            .lstRoute11.Height = lngOrg
            .lstRoute15.Height = lngOrg
            .lstRoute4.Height = lngOrg
            .lstRoute8.Height = lngOrg
            .lstRoute12.Height = lngOrg
            .lstRoute16.Height = lngOrg
            End With
       Case 2
            With Me
            .lstRoute1.Height = lngOrg
            .lstRoute5.Height = lngOrg
            .lstRoute9.Height = lngOrg
            .lstRoute13.Height = lngOrg
            .lstRoute2.Height = lngOrg
            .lstRoute6.Height = lngOrg
            .lstRoute10.Height = lngOrg
            .lstRoute14.Height = lngOrg
            .lstRoute3.Height = lngLarge
            .lstRoute7.Height = lngLarge
            .lstRoute11.Height = lngLarge
            .lstRoute15.Height = lngLarge
            .lstRoute4.Height = lngOrg
            .lstRoute8.Height = lngOrg
            .lstRoute12.Height = lngOrg
            .lstRoute16.Height = lngOrg
            End With
       Case 3
            With Me
            .lstRoute1.Height = lngOrg
            .lstRoute5.Height = lngOrg
            .lstRoute9.Height = lngOrg
            .lstRoute13.Height = lngOrg
            .lstRoute2.Height = lngOrg
            .lstRoute6.Height = lngOrg
            .lstRoute10.Height = lngOrg
            .lstRoute14.Height = lngOrg
            .lstRoute3.Height = lngOrg
            .lstRoute7.Height = lngOrg
            .lstRoute11.Height = lngOrg
            .lstRoute15.Height = lngOrg
            .lstRoute4.Height = lngLarge
            .lstRoute8.Height = lngLarge
            .lstRoute12.Height = lngLarge
            .lstRoute16.Height = lngLarge
            End With
        Case 4
            With Me
            .lstRoute1.Height = lngOrg
            .lstRoute5.Height = lngOrg
            .lstRoute9.Height = lngOrg
            .lstRoute13.Height = lngOrg
            .lstRoute2.Height = lngOrg
            .lstRoute6.Height = lngOrg
            .lstRoute10.Height = lngOrg
            .lstRoute14.Height = lngOrg
            .lstRoute3.Height = lngOrg
            .lstRoute7.Height = lngOrg
            .lstRoute11.Height = lngOrg
            .lstRoute15.Height = lngOrg
            .lstRoute4.Top = lngOrgH
            .lstRoute4.Height = lngOrg
            .lstRoute8.Top = lngOrgH
            .lstRoute8.Height = lngOrg
            .lstRoute8.Top = lngOrgH
            .lstRoute12.Height = lngOrg
            .lstRoute12.Top = lngOrgH
            .lstRoute16.Height = lngOrg
            .lstRoute16.Top = lngOrgH
            End With
        End Select
    End Select

  12. #12
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    436
    you can further "shorten" it:
    Code:
    Dim lngOrg As Long, lngLarge As Long, lngOrgH As Long, lngNewH As Long
    lngOrg = 2210
    lngLarge = 4962
    lngOrgH = 11291
    lngNewH = 8558
    
    
    
    
    Dim strPath As String, strFile As String
    
    
    
    
    With Me
        intMainIndex = .tbcMainMenu.value ' Tab Page Index
        intIndex = .cboOption7.ListIndex 'Combo Index
        
        
        Select Case intMainIndex
        Case 2 'VIEW ROUTES
            Select Case intIndex
            Case 0 ' LISTS 1,5,9,13
                .lstRoute1.Height = lngLarge
                .lstRoute5.Height = lngLarge
                .lstRoute9.Height = lngLarge
                .lstRoute13.Height = lngLarge
                .lstRoute2.Height = lngOrg
                .lstRoute6.Height = lngOrg
                .lstRoute10.Height = lngOrg
                .lstRoute14.Height = lngOrg
                .lstRoute3.Height = lngOrg
                .lstRoute7.Height = lngOrg
                .lstRoute11.Height = lngOrg
                .lstRoute15.Height = lngOrg
                .lstRoute4.Height = lngOrg
                .lstRoute8.Height = lngOrg
                .lstRoute12.Height = lngOrg
                .lstRoute16.Height = lngOrg
           Case 1
                .lstRoute1.Height = lngOrg
                .lstRoute5.Height = lngOrg
                .lstRoute9.Height = lngOrg
                .lstRoute13.Height = lngOrg
                .lstRoute2.Height = lngLarge
                .lstRoute6.Height = lngLarge
                .lstRoute10.Height = lngLarge
                .lstRoute14.Height = lngLarge
                .lstRoute3.Height = lngOrg
                .lstRoute7.Height = lngOrg
                .lstRoute11.Height = lngOrg
                .lstRoute15.Height = lngOrg
                .lstRoute4.Height = lngOrg
                .lstRoute8.Height = lngOrg
                .lstRoute12.Height = lngOrg
                .lstRoute16.Height = lngOrg
           Case 2
                .lstRoute1.Height = lngOrg
                .lstRoute5.Height = lngOrg
                .lstRoute9.Height = lngOrg
                .lstRoute13.Height = lngOrg
                .lstRoute2.Height = lngOrg
                .lstRoute6.Height = lngOrg
                .lstRoute10.Height = lngOrg
                .lstRoute14.Height = lngOrg
                .lstRoute3.Height = lngLarge
                .lstRoute7.Height = lngLarge
                .lstRoute11.Height = lngLarge
                .lstRoute15.Height = lngLarge
                .lstRoute4.Height = lngOrg
                .lstRoute8.Height = lngOrg
                .lstRoute12.Height = lngOrg
                .lstRoute16.Height = lngOrg
           Case 3
                .lstRoute1.Height = lngOrg
                .lstRoute5.Height = lngOrg
                .lstRoute9.Height = lngOrg
                .lstRoute13.Height = lngOrg
                .lstRoute2.Height = lngOrg
                .lstRoute6.Height = lngOrg
                .lstRoute10.Height = lngOrg
                .lstRoute14.Height = lngOrg
                .lstRoute3.Height = lngOrg
                .lstRoute7.Height = lngOrg
                .lstRoute11.Height = lngOrg
                .lstRoute15.Height = lngOrg
                .lstRoute4.Height = lngLarge
                .lstRoute8.Height = lngLarge
                .lstRoute12.Height = lngLarge
                .lstRoute16.Height = lngLarge
            Case 4
                .lstRoute1.Height = lngOrg
                .lstRoute5.Height = lngOrg
                .lstRoute9.Height = lngOrg
                .lstRoute13.Height = lngOrg
                .lstRoute2.Height = lngOrg
                .lstRoute6.Height = lngOrg
                .lstRoute10.Height = lngOrg
                .lstRoute14.Height = lngOrg
                .lstRoute3.Height = lngOrg
                .lstRoute7.Height = lngOrg
                .lstRoute11.Height = lngOrg
                .lstRoute15.Height = lngOrg
                .lstRoute4.Top = lngOrgH
                .lstRoute4.Height = lngOrg
                .lstRoute8.Top = lngOrgH
                .lstRoute8.Height = lngOrg
                .lstRoute8.Top = lngOrgH
                .lstRoute12.Height = lngOrg
                .lstRoute12.Top = lngOrgH
                .lstRoute16.Height = lngOrg
                .lstRoute16.Top = lngOrgH
            End Select
        End Select
    End With

  13. #13
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    Very neat and tidy jojowhite, as per post #8, this is why you are all GOAT on this

    Yes, having 1 x With block to accommodate the full procedure

    Kindest

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    I will have to be more explicit in future.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371
    GOAT includes you WGM

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

Similar Threads

  1. Modules and Object Overload
    By drexasaurus in forum Programming
    Replies: 4
    Last Post: 05-23-2014, 11:14 AM
  2. Object variable or With block variable not set
    By walter189 in forum Programming
    Replies: 1
    Last Post: 07-28-2011, 08:51 AM
  3. Long Variable syntax
    By eww in forum Programming
    Replies: 5
    Last Post: 02-10-2011, 03:34 PM
  4. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 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