Results 1 to 4 of 4
  1. #1
    ripcure is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Posts
    4

    Passing value from table in a subform to an array!

    Hello,



    I am very new to VBA & Access.

    I want to use the data populated in a table in the subform. I want to pass the value into an Array.

    Any help appreciated!

    Thanks and Regards!
    Ashish Naik

  2. #2
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    Ashish -

    Could you please provide some additional info...

    Do you want to populate the subform itself?

    OR,

    Are you looking to walk through the existing subform's records and place that data into an array for some other purpose?


    Please advise.

  3. #3
    ripcure is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    May 2011
    Posts
    4
    Yes, I am looking to walk through the exisitng subform's records and place that data into an array.

    Thanks and Regards!
    Ashish Naik

    Quote Originally Posted by ketbdnetbp View Post
    Could you please provide some additional info...

    Do you want to populate the subform itself?

    OR,

    Are you looking to walk through the existing subform's records and place that data into an array for some other purpose?


    Please advise.

  4. #4
    ketbdnetbp is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Midwest
    Posts
    254

    Ashish -

    You could try something along these lines:

    'You would, of course, need to add in your own error handling.

    1. Declare the Array in your/a module entitled arrays...

    Public arrMyArray() as Variant '(Set bounds/dimensions () at form level)

    2. From Main Form (choose appropriate event to fire code), then:

    Dim strSubformControl As String
    strSubformControl = "NameofSubform"
    DoCmd.GoToControl strSubformControl

    'This gets you to the subform

    'Then, you need to know the number of records

    Dim xTR As Long
    xTR = Forms!MainFormName!SubformName.Form.RecordsetClone .RecordCount


    'Double checks record count

    If xTR >= 1 Then
    Forms!MainFormName!SubformName.Form.RecordsetClone .MoveLast
    xTR = Forms!MainFormName!SubformName.Form.RecordsetClone .RecordCount
    End If

    '2 dimensions in array, 1 for number of records, 1 for number of fields
    'Re-Set array dimensions

    ReDim arrMyArray(1 to xTR, 1 to Number of Fields)

    'Example: ReDim arrMyArray(1 to xTR, 1 to 3)

    3. Then, you start reading the data

    If xTR = 1 Then
    DoCmd.GoToRecord acActiveDataObject, , acFirst
    'Record Counter
    Dim intC As Integer
    intC = 1
    arrMyArray(intC, 1) = Forms!MainFormName!SubformName.Form![Field1]
    arrMyArray(intC, 2) = Forms!MainFormName!SubformName.Form![Field2]
    arrMyArray(intC, 3) = Forms!MainFormName!SubformName.Form![Field3]
    'etc...
    end if

    If xTR >= 2 Then
    DoCmd.GoToRecord acActiveDataObject, , acFirst
    'Record Counter
    Dim intC2 As Integer
    intC2 = 1
    arrMyArray(intC2, 1) = Forms!MainFormName!SubformName.Form![Field1]
    arrMyArray(intC2, 2) = Forms!MainFormName!SubformName.Form![Field2]
    arrMyArray(intC2, 3) = Forms!MainFormName!SubformName.Form![Field3]
    'etc...

    do until intC2 = xTR
    DoCmd.GoToRecord acActiveDataObject, , acNext
    Debug.Print intC2
    intC2 = intC2 + 1
    arrMyArray(intC2, 1) = Forms!MainFormName!SubformName.Form![Field1]
    arrMyArray(intC2, 2) = Forms!MainFormName!SubformName.Form![Field2]
    arrMyArray(intC2, 3) = Forms!MainFormName!SubformName.Form![Field3]
    'etc...
    Loop

    end if

    Hope this gets you started.

    All the best,

    Jim

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

Similar Threads

  1. Passing focus to subform.....
    By smorelandii in forum Forms
    Replies: 3
    Last Post: 02-04-2011, 10:51 AM
  2. can i put the result in array?
    By dada in forum Programming
    Replies: 1
    Last Post: 08-19-2010, 07:17 PM
  3. Array of labels in runtime
    By ngruson in forum Programming
    Replies: 1
    Last Post: 08-19-2010, 07:30 AM
  4. Building Array
    By jgelpi16 in forum Forms
    Replies: 12
    Last Post: 03-22-2010, 12:33 PM
  5. How to use array? [ solved] Thanks.
    By wasim_sono in forum Programming
    Replies: 0
    Last Post: 10-20-2006, 12:00 AM

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