Hello all,
Am getting an error using code:
Run-time error '3075':
Syntax error (missing operator) in query expression '[CustomerID] IN ({selected items})
I have extended selection turned on; I can select listbox results with shift, control, but
when press spacebar to open selected records, error occurs.
for this form I downloaded:
... ad-hoc search ... which generates dynamic SQL and assigns it to a listbox on the
form to show the results. The form "frmSearch"
Limitations:
The form only allows searches on non-system tables and non-action, non-parameter queries.
A maximum of five fields (duplicates inclusive) can be used in one SQL statement. However, by selecting the "Edit SQL"
checkbox, additional criteria can be typed directly in the SQL textbox.
Multiple criteria can only be grouped together (using parenthesis) by directly editing the SQL textbox.
---- 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!frmSearch
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)
DoCmd.OpenForm stDocName, acNormal, , "[CustomerID] IN (" & strList & ")"
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
Am getting an error using code:
Run-time error '3075':
Syntax error (missing operator) in query expression '[CustomerID] IN ({selected items})
I have extended selection turned on; I can select listbox results with shift, control, but
when press spacebar to open selected records, error occurs.
for this form I downloaded:
... ad-hoc search ... which generates dynamic SQL and assigns it to a listbox on the
form to show the results. The form "frmSearch"
Limitations:
The form only allows searches on non-system tables and non-action, non-parameter queries.
A maximum of five fields (duplicates inclusive) can be used in one SQL statement. However, by selecting the "Edit SQL"
checkbox, additional criteria can be typed directly in the SQL textbox.
Multiple criteria can only be grouped together (using parenthesis) by directly editing the SQL textbox.
---- 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!frmSearch
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)
DoCmd.OpenForm stDocName, acNormal, , "[CustomerID] IN (" & strList & ")"
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