Reputation: 75
I have a form with 2 listboxs (list1 and list2) that displays the values from 2 YES/NO type fields. On the table the field data is represented by checkboxs but in the listbox it displays as True/False
I also have 2 comboboxes with Yes and No values which are used to populate/edit the field in the table.
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. i.e 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.
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. i.e 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.
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)
Upvotes: 0
Views: 1739
Reputation: 75
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
and it worked like a charm.
Upvotes: 1
Reputation: 79
Have you checked your List Box Properties values. On the Properties Windows then choose Data tab, You need to check the following properties :
Upvotes: 0