Results 1 to 3 of 3
  1. #1
    George is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    295

    VBA passing Array arguments to procedure

    Good day all.


    My problem is in the extract from my program below.
    The procedure call "Call RearrangeCoordinates(RearrangeCoords(), ReturnCoords())" return a message "Type mismatched: Array or user-defined type expected"
    Are there any views as to why the message is being displayed?

    Private Sub CommandButton1_Click()

    Dim ReturnCoords As Variant

    Dim ...........................................

    ArrayLength = UBound(ReturnCoords)
    ReDim RearrangeCoords(0 To ArrayLength) As Variant
    Call RearrangeCoordinates(RearrangeCoords(), ReturnCoords())
    ..........................................

    End Sub


    Public Sub RearrangeCoordinates(ByRef RearCoord() As Variant, ByRef ReturnCoords() As Variant)

    For q = 0 To 8 Step 2
    RearrangeCoords(q) = ReturnCoords(q + 1)
    RearrangeCoords(q + 1) = ReturnCoords(q)
    Next q

    End Sub

  2. #2
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your error is here: ArrayLength = UBound(ReturnCoords)

    ReturnCoords is not an array (Dim ReturnCoords As Variant), and it is the UBound function that is giving you the error.

    Why are you checking for the array size right after you declare it? If ReturnCoords is an array, and exists outside the sub and you want to reference it, remove the Dim statement for it.

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

Similar Threads

  1. VBA ByVal vs ByRef Passing Arguments
    By ylatodd in forum Programming
    Replies: 5
    Last Post: 10-22-2013, 02:49 PM
  2. Using Arguments in a Procedure to do calculation
    By murfeezlaw in forum Programming
    Replies: 8
    Last Post: 11-08-2012, 01:25 PM
  3. Replies: 0
    Last Post: 04-02-2012, 11:30 AM
  4. Replies: 4
    Last Post: 06-13-2011, 12:14 PM
  5. Replies: 3
    Last Post: 05-23-2011, 02:15 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