简体   繁体   English

MS-Access列表框链接到YES / NO类型字段的问题

[英]Troubles with an MS-Access Listbox linked to a YES/NO type field

I have a form with 2 listboxs (list1 and list2) that displays the values from 2 YES/NO type fields. 我有一个带有2个列表框(list1和list2)的窗体,该窗体显示2个YES / NO类型字段中的值。 On the table the field data is represented by checkboxs but in the listbox it displays as True/False 在表上,字段数据由复选框表示,但在列表框中,它显示为True / False
I also have 2 comboboxes with Yes and No values which are used to populate/edit the field in the table. 我也有2个带有是和否值的组合框,用于填充/编辑表中的字段。

I am trying to edit the VBA code of this form in such a way that the 2 listboxes (and values in the field) can not be true at the same time. 我正在尝试编辑这种形式的VBA代码,使两个列表框(以及字段中的值)不能同时为true。 ie if a user selects true on combo1 and hits save, the program will check the value in list2 and, if its also true, display an error message and exit the sub. 例如,如果用户在combo1上选择true,然后单击save,则程序将检查list2中的值,如果也为true,则显示错误消息并退出子菜单。

i have found that the values are actually saved as 0's and -1's in the list box but my problem is that the value of the list box doesnt change even after changing the value on the table. 我发现值实际上在列表框中保存为0和-1,但是我的问题是,即使更改表上的值,列表框的值也不会更改。 ie even though the True/False Values changes accordinly when the value on the table field is changed, the 0's and 1's dont change (found this out by msgboxing the values on the listbox) and this makes it impossible to compare values before saving. 即,即使更改表字段中的值时True / False值一致变化,也不会更改0和1(通过将列表框上的值msgbox找出来),这使得在保存之前无法比较值。

An example of the code i am using is below 我正在使用的代码示例如下

...   

 List2.Requery
'MsgBox List2

 'MsgBox Combo1
If Combo1 = "True" And List2.Value = "-1" Then
MsgBox "List1 and List2 cannot be TRUE at the same time. Please adjust or cancel edit"     
Exit Sub
Else
myr.Edit
myr![Y/Nfield] = Combo1
myr.Update


Set myr = Nothing 'Close the recordeset 


End If

...

(the ... means there are codes before and after this bit) (...表示此位前后有代码)

Just incase one comes to this later and really needs answer here's how i solved this... 万一一个人后来遇到这个并且真的需要答案,这就是我解决这个问题的方法...

instead of using the list2.value property (refer to code in question) i used list.itemdata(0) which points to the first column of my listbox 而不是使用list2.value属性(请参阅有问题的代码),我使用的是list.itemdata(0),它指向我的列表框的第一列

and it worked like a charm. 它就像一种魅力。

Have you checked your List Box Properties values. 您是否检查了列表框属性值。 On the Properties Windows then choose Data tab, You need to check the following properties : 在“属性”窗口上,然后选择“数据”选项卡,您需要检查以下属性:

  1. Row Source Type, should be Table/Query 行源类型,应为表/查询
  2. Row Source, should be filled with your corresponding table name 行源,应填写您对应的表名
  3. Bound Column, should be filled with your column index of your table that you wish to view on the listbox 绑定列,应使用要在列表框上查看的表的列索引填充

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM