Results 1 to 5 of 5

Thread: [RESOLVED] Stuck in Retrieving an array

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Resolved [RESOLVED] Stuck in Retrieving an array

    Hello again experts
    I was able to save ceckboxes' indexes by means of tis code
    Code:
    StrSql = "Select * from Transac_tbl where ID =" _
                  & Text3.Text & ""
        RS.Open StrSql, DB, adOpenDynamic, adLockOptimistic
    For i = 1 To Check1.Count - 1
    If Check1(i).Value = 1 Then
    If RS.EOF Or RS.BOF Then RS.AddNew
     RS!ID = Text3.Text
     RS!Vac_ID = Check1(i).Index
     RS.Update
     RS.MoveNext
     End If
     Next
    The following piture illustrates what I'm doing.
    Name:  18-12-2018 20-45-19.jpg
Views: 154
Size:  13.4 KB

    Now I need to retrieve the checkboxes values as shown in the piture below.
    Name:  18-12-2018 20-41-48.jpg
Views: 156
Size:  7.0 KB

    This is what I'm doing:
    Code:
    StrSql = "Select * from Transac_tbl where ID =" _
                  & Text3.Text & ""
        RS.Open StrSql, DB, adOpenDynamic, adLockOptimistic
    If Not RS.EOF Then
    For i = 1 To RS.RecordCount
    Check1(i).Value = 1
    Next
    End If
    unfortunately the output of this query is this:
    Name:  18-12-2018 21-04-18.jpg
Views: 147
Size:  6.7 KB
    thank you

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Stuck in Retrieving an array

    I'm going to give you the answer by asking a question: So you saved the index of the checkbox, but then didn't bother to use it when reading it back?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Stuck in Retrieving an array

    techgnome
    thank you for your interest
    So you think there is no way to retrieve them appropriately?
    This is the way I thougt I could read them back
    Code:
    If Not RS.EOF Then
    For i = 1 To RS.RecordCount
    Check1(i).Value = 1
    Next
    End If
    but didn't work

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Stuck in Retrieving an array

    Of course there is a way. You have to use the proper index as mentioned above and in the other thread.

    This is what you have
    Code:
    For i = 1 To RS.RecordCount
    Check1(i).Value = 1
    Next
    The code above will set the first x checkboxes to 1 based on the number of records in the recordset. It does not care which are supposed to be set to 1. In fact it does not even look at the data of the records just the total number of them.

    It should be more like
    Code:
    For i = 1 To RS.RecordCount
    Check1(RS!Vac_ID).Value = 1
    Next
    This piece sets the correct checkbox to 1 based on the index that was saved into the database

    Edit: There is also no reason to use a For Next loop here I would go with something like
    Code:
    Do Until RS.EOF
    Check1(RS!Vac_ID).Value = 1
    Loop
    Last edited by DataMiser; Dec 18th, 2018 at 03:38 PM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: Stuck in Retrieving an array

    DataMiser
    So grateful to you
    it worked perfect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width