Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

列表框数据相互转移问题

Lucas Wang  发表于:2015-02-10 15:20:03  
复制

本人根据http://www.accessoft.com/article-show.asp?id=5207的方法制作列表框窗体将两个表中的数据相互传输,但是在我自己的内容中运行相应的代码就出现“3421错误代码,数据类型转换错误”或者“错误64224,方法Value用于对象Field2失败”,代码如下,错误指向加粗部分,求解,谢谢

Private Sub Command4_Click()
    
    Dim rst As DAO.Recordset
    Dim intI As Integer
    Dim intIndex As Integer
        
    If Me.List0.ListCount <> 0 Then
        intIndex = Me.List0.ListIndex
        Set rst = CurrentDb.OpenRecordset("tblFixedAssetDisposal", , dbAppendOnly)
        rst.AddNew
        For intI = 1 To rst.Fields.Count - 1
            rst.Fields(intI).Value = Me.List0.Column(intI)
        Next
        rst.Update
        rst.Close
        CurrentDb.Execute "DELETE FROM tblFixedAsset1 WHERE ID=" & Me.List0
        Me.List0.Requery
        Me.List1.Requery
        Me.List0 = Null
        If Me.List0.ListCount <> 0 Then
            If intIndex >= Me.List0.ListCount - 1 Then
                intIndex = Me.List0.ListCount - 1
            Else
                intIndex = intIndex + 1
            End If
            Me.List0 = Me.List0.ItemData(intIndex)
        End If
    End If


End Sub

 

Top
煮江品茶 发表于:2015-02-10 16:39:21
在这句之前加一句:msgbox rst.fields(inti).name & "=" & Me.List0.Column(intI)
看看是不是闹出笑话来了


Lucas Wang 发表于:2015-02-10 17:08:25
煮江品茶,你好,谢谢你的答复,还是没明白,加入你的代码后弹出窗口显示选中的记录的各个列的信息,到了记录的某个列没有内容的时候就会提示“错误64224,方法Value用于对象Field2失败”,我是新手,对代码只了解一点,还请详解,谢谢

煮江品茶 发表于:2015-02-10 17:28:45

你已经发现问题了嘛,说明某个字段不能为null嘛。这样的话,可以这样修改:


rst.Fields(intI).Value = nz(Me.List0.Column(intI))






总记录:3篇  页次:1/1 9 1 :