By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

How to return 2d Array from a Function?

P: 2
My code:
Expand|Select|Wrap|Line Numbers
  1. Public Function PNL(Model As String, Station As String) As Variant
  2.     Dim tbl As DAO.Recordset
  3.     Dim BodyFrom As Double
  4.     Dim BodyTo As Double
  5.     Dim i As Double
  6.     Dim Box As String, PNum As String, MaxLot As Long
  7.     Dim BFZ()
  8.  
  9.     Set tbl = CurrentDb.OpenRecordset("_0_Thong_Tin_Ve_Box")
  10.     tbl.MoveFirst
  11.     had_Box = False
  12.     i = 1
  13.     Do Until tbl.EOF
  14.         If tbl!ModelType = Model And tbl!Matram = Station Then
  15.             Box = tbl!Box
  16.             PNum = tbl!partnumber
  17.             MaxLot = tbl!MaxLot
  18.             ReDim BFZ(1 To i, 1 To 3)
  19.             BFZ(i, 1) = PNum
  20.             BFZ(i, 2) = Box
  21.             BFZ(i, 3) = MaxLot
  22.  
  23.             PNL = BFZ()
  24.             had_Box = True
  25.             Debug.Print BFZ(i, 2)
  26.             i = i + 1
  27.  
  28.         End If
  29.         tbl.MoveNext
  30.     Loop
  31.     If had_Box = True Then Exit Function
  32.     ReDim BFZ(1 To 1, 1 To 3)
  33.     BFZ(1, 1) = "Empty"
  34.     BFZ(1, 2) = ""
  35.     BFZ(1, 3) = ""
  36.     PNL = BFZ()
  37. End Function
  38.  
  39.  
I call it and show result but it empty although it have data
Expand|Select|Wrap|Line Numbers
  1.  PNLf = PNL(Model, MaStation_tx) ' Get PNum, Box va MaxLot
  2.                     u1 = UBound(PNLf, 1)
  3.                    box = PNLf(1, 2)
  4.                     Debug.Print box
Please help me, many thanks
Dec 13 '19 #1
Share this Question
Share on Google+
2 Replies


P: 65
You can't use ReDim this way. Study the documentation:
ReDim Statement

You can use the GetRows method of a recordset to retrieve the records' field values in an array.
Dec 14 '19 #2

P: 2
I will try
Thanks cactusdata
Dec 14 '19 #3

Post your reply

Sign in to post your reply or Sign up for a free account.