对于回路VB6双重故障. [英] For Loop VB6 Double Entry Malfunction.

查看:81
本文介绍了对于回路VB6双重故障.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家们.我不知道下面的循环有问题.但是,当我调用此函数时,它应该将列表框中的记录插入到数据库访问数据库表中.但它会将第一条记录保存两次. ,我做错了吗?
例如
产品代码
124318N麦卡特
124318N麦卡特
141652G米饭

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

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

推荐答案

我不确定这是否有帮助,但是为什么要使用For i = 1 To lvprod.ListItems.Count?不在VB中列出零吗?如果是这样,我将其更改为For i = 0 To lvprod.ListItems.Count - 1,然后在调试器中单步执行代码以查看出现问题的地方.
I''m not sure this helps, but why are you using For i = 1 To lvprod.ListItems.Count? Aren''t Lists zero based in VB? If so, I''d change it to For i = 0 To lvprod.ListItems.Count - 1, then step through the code in the debugger to see where it''s getting something wrong.


这篇关于对于回路VB6双重故障.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆