Results 1 to 12 of 12

Thread: For Loop VB6 Double Entry Malfunction.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    71

    For Loop VB6 Double Entry Malfunction.

    Hi Experts. I dont know wats wrong with the loop below. But when i call this function its supposed to insert the records in a listbox into a db access db table. but it saves the first record twice. Wat could i be doing wrong?
    e.g
    Product Code
    124318N Mkate
    124318N Mkate
    141652G Rice
    Code:
    Sub AddToList()
    With dbData.Recordset
    For i = 1 To lvprod.ListItems.Count
     .AddNew
        .Fields(0) = lvprod.ListItems(i).Text 'prod code
        .Fields(1) = lvprod.ListItems(i).SubItems(2)
        .Fields(2) = txtPrice.Text  'price
        .Fields(3) = lvprod.ListItems(i).SubItems(1) 'qty
        .Fields(4) = 0
        .Fields(5) = lvprod.ListItems(i).SubItems(4)
        .Fields(6) = Month(Now)
        .Fields(7) = Year(Now)
        .Update
        Next i
    dbData.Refresh
    End With
        End Sub

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: For Loop VB6 Double Entry Malfunction.

    Patoh

    At first glance, nothing pops out.
    Could you perhaps attach an image of your ListBox

    Spoo

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    71

    Re: For Loop VB6 Double Entry Malfunction.

    Here the list box image.
    Attached Images Attached Images  

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: For Loop VB6 Double Entry Malfunction.

    Patoh

    That helps, sort of ...
    In your OP, your unexpected output was ...

    124318N Mkate
    124318N Mkate
    141652G Rice

    Where did Rice come from?
    Did it appear even though the ListBox contained only 1 item?

    EDIT:
    Two other thoughts:
    1. Is it possible that you got 2 instances of Mkate because you ran
      your app twice (perhaps while you were testing it) and your app did
      not "recognize" that a record for Mkate already existed?
    2. If that isn't the issue (ie, your RecordSet truly has no records before
      each time you run your app), have you tried setting a BreakPoint and
      stepping through the loop. Could the 2nd instance of Mkate be coming
      from somewhere else?


    Spoo
    Last edited by Spoo; Jun 18th, 2011 at 09:01 AM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    71

    Re: For Loop VB6 Double Entry Malfunction.

    Thanx for the rep Spoo.. when I just put one product. Mkate in the list box. the reicpt i generate from that sale has only that 1 product. but when i put 2 products mkate and rice the receipt shows
    124318N Mkate
    124318N Mkate
    141652G Rice
    just as the db table looks.. I dont know whats wrong. i was thinkin it was the loop adding products to the db table. the for loop.

  6. #6

  7. #7
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: For Loop VB6 Double Entry Malfunction.

    Patoh

    At the risk of being repetitive, it seems like you running your app twice
    1. just with Mkate in ListView .. print
    2. add Rice, rerun .. print

    Sounds like the problem is that the 2nd time you run your app, it is adding
    Mkate again -- because you told it to !!

    Seems like you need to add an algo to check if Mkate exists in the recordset.
    If it does, then do not add a second record.

    EDIT:
    To incorporate Marty's observation

    Spoo
    Last edited by Spoo; Jun 18th, 2011 at 09:57 AM.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    71

    Re: For Loop VB6 Double Entry Malfunction.

    Thanx Martin. My Bad.. The List View...

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    71

    Re: For Loop VB6 Double Entry Malfunction.

    Spoo .. The Table I store the Records is Temporary Until the transcation is printed. then the table is cleared. so that the next transaction can take place. the table holds only one transaction per go. wen the receipt is printed the table is cleared out.So theres no chance of the records recurring.

  10. #10
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: For Loop VB6 Double Entry Malfunction.

    Patoh

    OK, good to hear. Scratch that idea off the list

    All I have at this point is my suggestion #2 in post #4 -- step through the code.

    BTW, in your "problem" situation, how many records are in the temp recordset?
    If there are only 2 (as there should be), then perhaps the problem stems from
    the sub (which you did not show) that does the printing itself.

    Spoo

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    71

    Re: For Loop VB6 Double Entry Malfunction.

    If ts just one record then theres no repetation. But if there are 2 or more records then the repation occurs. the sub printing gets the value from the temp table. Heres the whole code for the Pos System.
    Attached Files Attached Files

  12. #12
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: For Loop VB6 Double Entry Malfunction.

    Patoh

    I'm guessing that Private Function thermalprint() does the
    printing.

    I did not read all your code, but if the above guess is correct,
    perhaps you could put a breakpoint in this function to see
    how many times it is being called and if it is working as you intended.

    Spoo

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