Syntax Error in Code

G

Guest

Hello All,

I am having some severe difficulties trying to code a listbox. What I am
attempting to do is use a listbox to search a text field in a table. The
problem is that the listbox is looking for a numeric value in the field, and
not a text value. I need to have the code work so it will return a text
value. Below is part of the code that is giving me the problem. I know that
I have to insert two comas (') in the code but I always get syntax errors.
Any help would be greatly appreciated. Here is the code:

Private Function IncludeEmployeeName()
On Error GoTo ProcError

Dim varEmployee As Variant
Dim strTemp As String

For Each varEmployee In Me!lboEmployeeToInclude.ItemsSelected()

strTemp = strTemp & "[strEmpName] = " & _
Me!lboEmployeeToInclude.ItemData(varEmployee ) & " Or "
Next

If Len(strTemp ) > 0 Then
IncludeEmployeeName = "(" & Left$(strTemp , Len(strTemp ) - 4) & ")"
Else
IncludeEmployeeName = ""
End If

ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in IncludeEmployeeName Function..."
Resume ExitProc
End Function

Regards
 
K

Ken Snell [MVP]

Delimit the value with ' characters; e.g.,

strTemp = strTemp & "[strEmpName] = '" & _
Me!lboEmployeeToInclude.ItemData(varEmployee ) & "' Or "
 
G

Guest

That did the trick Ken...Thank you for your help!!

Ken Snell said:
Delimit the value with ' characters; e.g.,

strTemp = strTemp & "[strEmpName] = '" & _
Me!lboEmployeeToInclude.ItemData(varEmployee ) & "' Or "

--

Ken Snell
<MS ACCESS MVP>

Lowrider72 said:
Hello All,

I am having some severe difficulties trying to code a listbox. What I am
attempting to do is use a listbox to search a text field in a table. The
problem is that the listbox is looking for a numeric value in the field,
and
not a text value. I need to have the code work so it will return a text
value. Below is part of the code that is giving me the problem. I know
that
I have to insert two comas (') in the code but I always get syntax errors.
Any help would be greatly appreciated. Here is the code:

Private Function IncludeEmployeeName()
On Error GoTo ProcError

Dim varEmployee As Variant
Dim strTemp As String

For Each varEmployee In Me!lboEmployeeToInclude.ItemsSelected()

strTemp = strTemp & "[strEmpName] = " & _
Me!lboEmployeeToInclude.ItemData(varEmployee ) & " Or "
Next

If Len(strTemp ) > 0 Then
IncludeEmployeeName = "(" & Left$(strTemp , Len(strTemp ) - 4) & ")"
Else
IncludeEmployeeName = ""
End If

ExitProc:
Exit Function
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in IncludeEmployeeName Function..."
Resume ExitProc
End Function

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top