Hi all,
Here is the story (I am using Access 97):
1. I have a form with 2 listboxes (List0 and List1) and 1 text box.
2. List0 is set to Value list with following values: "item 1;item 2;item 3"
3. List1 is populated and selected in the List0_AfterUpdate event like this:
Code:
Private Sub List0_AfterUpdate()
List1.RowSource = "SELECT Field2 FROM Table1 WHERE Field1 = '" & List0 & "'"
List1.Requery
List1.Selected(List0.ListIndex) = True
End Sub
The above works perfectly fine until I try to type something into the text box (or use any other control on the form). What happens is: I am unable to set the focus into the text box by clicking it so I can never type any value into it. If I try using a command button same thing happens; nothing executes. When I ran the code in debug, I noticed that for some reason the List0_AfterUpdate event executes whenever I click on the text box. I don't understand why this happens even though I have never changed a value in the List0 listbox.
When I change the event code to the following everything works as it is supposed to (the event never executes after clicking the text box):
Code:
Private Sub List0_AfterUpdate()
List1.RowSource = "SELECT Field2 FROM Table1 WHERE Field1 = '" & List0 & "'"
List1.Requery
Select Case List0
Case "item 1"
List1 = "item 1, 1"
Case "item 2"
List1 = "item 2, 2"
Case "item 3"
List1 = "item 3, 3"
End Select
End Sub
Since the only difference between the 2 pieces of code is using the "Selected" property vs setting the value with the "=" sign, I think that this issue is somehow tied into the "Selected" property.
The problem is that in my code I have to use "Selected" property to set the List1 value, becasue sometimes there are repeated values in List1.
Has anyone encountered something like this before?
Any comments would be appreciated.
Jaroslaw
Here is the story (I am using Access 97):
1. I have a form with 2 listboxes (List0 and List1) and 1 text box.
2. List0 is set to Value list with following values: "item 1;item 2;item 3"
3. List1 is populated and selected in the List0_AfterUpdate event like this:
Code:
Private Sub List0_AfterUpdate()
List1.RowSource = "SELECT Field2 FROM Table1 WHERE Field1 = '" & List0 & "'"
List1.Requery
List1.Selected(List0.ListIndex) = True
End Sub
The above works perfectly fine until I try to type something into the text box (or use any other control on the form). What happens is: I am unable to set the focus into the text box by clicking it so I can never type any value into it. If I try using a command button same thing happens; nothing executes. When I ran the code in debug, I noticed that for some reason the List0_AfterUpdate event executes whenever I click on the text box. I don't understand why this happens even though I have never changed a value in the List0 listbox.
When I change the event code to the following everything works as it is supposed to (the event never executes after clicking the text box):
Code:
Private Sub List0_AfterUpdate()
List1.RowSource = "SELECT Field2 FROM Table1 WHERE Field1 = '" & List0 & "'"
List1.Requery
Select Case List0
Case "item 1"
List1 = "item 1, 1"
Case "item 2"
List1 = "item 2, 2"
Case "item 3"
List1 = "item 3, 3"
End Select
End Sub
Since the only difference between the 2 pieces of code is using the "Selected" property vs setting the value with the "=" sign, I think that this issue is somehow tied into the "Selected" property.
The problem is that in my code I have to use "Selected" property to set the List1 value, becasue sometimes there are repeated values in List1.
Has anyone encountered something like this before?
Any comments would be appreciated.
Jaroslaw