Hello all,
The following code works for 1 form but not this form (frmAndOr). Get error when try to open a query results form (frmCustomer) to show records selected in listbox (extended selection).
Thanks
John
---- code
Private Sub lstResult_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 32 ' vbKeySpace key
KeyCode = 32 ' this is the "revaluation"
' that kills the escape key action
'Open frmCustomer based on the ID from lstResult listbox
Dim stDocName As String
stDocName = "frmCustomer"
Dim frm As Form, ctl As Control
Dim varItm As Variant
Dim strList As String
strList = ""
Set frm = Forms!frmAndOr
Set ctl = frm!lstResult
For Each varItm In ctl.ItemsSelected
strList = strList & "'" & ctl.ItemData(varItm) & "', "
'Debug.Print ctl.ItemData(varItm)
Next varItm
strList = Left(strList, Len(strList) - 2)
If IsLoaded("frmCustomer") = False Then
DoCmd.OpenForm stDocName, acNormal, , "[CustomerID] IN (" & strList & ")"
End If
Case Else ' just in case you want to
' take a look at the key code generated
' by other keystrokes
'MsgBox KeyCode ' comment this out when it annoys you
End Select
End Sub
----
Private Sub cmdExit_Click()
If IsLoaded("frmCustomer") = True Then
Forms!frmCustomer.RecordSource = "qdfAll"
End If
Me.SetFocus
DoCmd.Close acForm, Me.Name
End Sub
The following code works for 1 form but not this form (frmAndOr). Get error when try to open a query results form (frmCustomer) to show records selected in listbox (extended selection).
Thanks
John
---- code
Private Sub lstResult_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 32 ' vbKeySpace key
KeyCode = 32 ' this is the "revaluation"
' that kills the escape key action
'Open frmCustomer based on the ID from lstResult listbox
Dim stDocName As String
stDocName = "frmCustomer"
Dim frm As Form, ctl As Control
Dim varItm As Variant
Dim strList As String
strList = ""
Set frm = Forms!frmAndOr
Set ctl = frm!lstResult
For Each varItm In ctl.ItemsSelected
strList = strList & "'" & ctl.ItemData(varItm) & "', "
'Debug.Print ctl.ItemData(varItm)
Next varItm
strList = Left(strList, Len(strList) - 2)
If IsLoaded("frmCustomer") = False Then
DoCmd.OpenForm stDocName, acNormal, , "[CustomerID] IN (" & strList & ")"
End If
Case Else ' just in case you want to
' take a look at the key code generated
' by other keystrokes
'MsgBox KeyCode ' comment this out when it annoys you
End Select
End Sub
----
Private Sub cmdExit_Click()
If IsLoaded("frmCustomer") = True Then
Forms!frmCustomer.RecordSource = "qdfAll"
End If
Me.SetFocus
DoCmd.Close acForm, Me.Name
End Sub