If EmployeeID is text, you need to enclose the values in quotes:
For Each varItem In Me.ActiveContro l.ItemsSelected
strTemp = strTemp & "((tblEmployees .EmployeeID) = " & Chr$(34)
Me.ActiveContro l.ItemData(varI tem) & Chr$(34) & ") Or "
Next
(Chr$(34) is ")
However, I think it would probably be better to use:
Private Sub List2_AfterUpda te()
Dim varItem As Variant
Dim strTemp As String
Dim strSQL As String
Dim db As DAO.Database
Dim qry As QueryDef
strSQL = "SELECT tblEmployees.Em ployeeID, tblEmployees.[LName] & "",
"" & [FName] & "" "" & [MName] as Employees FROM tblEmployees "
For Each varItem In Me.ActiveContro l.ItemsSelected
strTemp = strTemp & Chr$(34) & Me.ActiveContro l.ItemData(varI tem) &
Chr$(34) & ", "
Next
strSQL = strSQL & "WHERE tblEmployees.Em ployeeID IN (" & Left(strTemp,
Len(strTemp) - 2) &
");"
' On Error Resume Next
Set db = CurrentDb
With db
.QueryDefs.Dele te "qryEmploye e"
Set qry = .CreateQueryDef ("qryEmploye e", strSQL)
End With
End Sub
Otherwise, your SQL string may grow to be too large.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
<Ly***********@ yahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I'm having problems with the following,
I originally had a PKnumber EmployeeID then had to change it to a text
field so it would accept both numbers and letters. Now it doesn't
work. Any suggestions?
Private Sub List2_AfterUpda te()
Dim varItem As Variant
Dim strTemp As String
Dim strSQL As String
Dim db As DAO.Database
Dim qry As QueryDef
strSQL = "SELECT tblEmployees.Em ployeeID, tblEmployees.[LName] & "",
"" & [FName] & "" "" & [MName] as Employees FROM tblEmployees "
For Each varItem In Me.ActiveContro l.ItemsSelected
strTemp = strTemp & "((tblEmployees .EmployeeID) = " &
Me.ActiveContro l.ItemData(varI tem) & ") Or "
Next
strSQL = strSQL & "WHERE (" & Left(strTemp, Len(strTemp) - 4) &
");"
' On Error Resume Next
Set db = CurrentDb
With db
.QueryDefs.Dele te "qryEmploye e"
Set qry = .CreateQueryDef ("qryEmploye e", strSQL)
End With
End Sub
Thanks.