A
Arvi Laanemets
Hi
I'm trying to create a continous form which includes 2 linked combos, let's
name them Group and Item - selection in first determines available
selections in second. At moment I can select between 2 possible solutions,
which both aren't perfect.
1. In LostFocus event, the 2nd combo is requeried. All works well, unless I
move to same (Item) control on another row. When I move to same control, in
all rows with different Group, Item controls are displayed as empty.
2. In LostFocus event, the form is requeried. In this case Item control
always displays proper value for all rows, but the first control of same row
is activated. I have to click on destination control twice to activate it.
Now my question. Is there a relatively easy way to determine in LostFocus
event, which control on which row was attempted to activate (trough mouse,
or from keyboard like arrow key or Enter or Tab, or from form's record
selector, etc.), so I can improve the 2nd solution? (Otherwise I probably
prefer the 1st solution as less evil).
The code used:
Private Sub cbbItem_Enter()
If Nz(Me!cbbGroup) = 0 Then
MsgBox ("Select Group before!")
Me!cbbGroup.Enabled = True
Me!cbbGroup.SetFocus
Exit Sub
End If
cbbItem.RowSource = _
"SELECT [Items].[Item], " & _
"[Items].[Name] " & _
"FROM Items" & _
"WHERE (((Items.Group)=" & Me![cbbGroup] & "));"
End Sub
Private Sub cbbItem_LostFocus()
cbbItem.RowSource = "SELECT [Items].[Item], " & _
"[Items].[Name] " &_
"FROM Items;"
' For 2nd solution, from here until end of sub, comments and code rows
are reversed
' Dim CurrentRecord As Variant
' CurrentRecord = Me.Bookmark
Me!cbbItem.Requery
' Me.Requery
'Me.Bookmark = CurrentRecord
End Sub
Private Sub Form_Current()
If Nz(Me!cbbItem) = 0 Then
Me!cbbGroup.Enabled = True
Me!cbbGroup.SetFocus
Else
Me!cbbGroup.Enabled = False
End If
End Sub
Thanks in advance!
Arvi Laanemets
I'm trying to create a continous form which includes 2 linked combos, let's
name them Group and Item - selection in first determines available
selections in second. At moment I can select between 2 possible solutions,
which both aren't perfect.
1. In LostFocus event, the 2nd combo is requeried. All works well, unless I
move to same (Item) control on another row. When I move to same control, in
all rows with different Group, Item controls are displayed as empty.
2. In LostFocus event, the form is requeried. In this case Item control
always displays proper value for all rows, but the first control of same row
is activated. I have to click on destination control twice to activate it.
Now my question. Is there a relatively easy way to determine in LostFocus
event, which control on which row was attempted to activate (trough mouse,
or from keyboard like arrow key or Enter or Tab, or from form's record
selector, etc.), so I can improve the 2nd solution? (Otherwise I probably
prefer the 1st solution as less evil).
The code used:
Private Sub cbbItem_Enter()
If Nz(Me!cbbGroup) = 0 Then
MsgBox ("Select Group before!")
Me!cbbGroup.Enabled = True
Me!cbbGroup.SetFocus
Exit Sub
End If
cbbItem.RowSource = _
"SELECT [Items].[Item], " & _
"[Items].[Name] " & _
"FROM Items" & _
"WHERE (((Items.Group)=" & Me![cbbGroup] & "));"
End Sub
Private Sub cbbItem_LostFocus()
cbbItem.RowSource = "SELECT [Items].[Item], " & _
"[Items].[Name] " &_
"FROM Items;"
' For 2nd solution, from here until end of sub, comments and code rows
are reversed
' Dim CurrentRecord As Variant
' CurrentRecord = Me.Bookmark
Me!cbbItem.Requery
' Me.Requery
'Me.Bookmark = CurrentRecord
End Sub
Private Sub Form_Current()
If Nz(Me!cbbItem) = 0 Then
Me!cbbGroup.Enabled = True
Me!cbbGroup.SetFocus
Else
Me!cbbGroup.Enabled = False
End If
End Sub
Thanks in advance!
Arvi Laanemets