Ms Access AddItem与VBA [英] Ms Access AddItem with VBA

查看:142
本文介绍了Ms Access AddItem与VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的表格.该按钮基本上将记录从一个表复制到另一个表. 在读取和复制记录时,还将检查特定值.例如.如果表中的一个字段的值为",则应调用另一种允许我输入日期的表格.输入日期并关闭表格后,程序将继续进行复制. 也有可能正在复制的表中的关键字段重复.在这种情况下,我应该启动一个列表框表单",并使用一个列表框显示重复记录的值.然后,我应该选择需要复制的正确记录.

I have a Form that has a button on it. The button basically copies records from one Table to the other. As records are read and copied, it is also checked for specific values. E.g. If one of the fields in the table has a value of "" then it should call another form that allows me to enter a date. Once the date is entered and the form is closed the programme carries on with copying. It can also happen that the key fields in the table that is being copied are duplicate. In this case I should a 'listbox form' should be launched with a listbox displaying the values of the duplicate records. I should then select the correct record that I need copied.

 Dim NumberCount As Long
     NumberCount = RecordsetElementValue.RecordCount
     If NumberCount > 1 Then
         With Form_F_ListBox.List30
             RecordsetElementValue.MoveFirst
             Do
                With Forms!F_ListBox.List30.AddItem(RecordsetElementValue!E_ElementValue)
                End With
                RecordsetElementValue.MoveNext
             Loop Until RecordsetElementValue.EOF = True
             DoCmd.OpenForm "F_ListBox", acNormal
         End With
     End If

上面的代码示例是我的工作,以防重复记录(NumberCount> 1) F_ListBox表单中的列表框应填充记录集中的值.

The code sample above is what I have for in case there are duplicate records (NumberCount > 1) The listbox in my F_ListBox form should be filled with the values in my recordset.

我现在遇到运行时错误6014.必须将RowSourceType属性设置为值列表"才能使用此方法.

I now run into a runtime error 6014. The RowSourceType property must be set to 'Value List' to use this method.

我在做什么错了?

推荐答案

在MS Access中设置组合框或列表框的行源的常用方法是使用SQL语句,但是,您也可以使用列表.这由行源类型控制.

The usual way to set the row source of a combo or list box in MS Access is to use an SQL statement, however, you can also use a list. This is controlled by the row source type.

Me.MylistBox.RowSourceType = "Value List"

从您的笔记中看来,用于行源的SQL语句会更容易:

From your notes, it seems that an SQL statement for the row source would be easier:

Me.MylistBox.RowSource = "SELECT ID FROM MyTable"

这篇关于Ms Access AddItem与VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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