473,804 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multi-select List box with textPK

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.

Nov 13 '05 #1
5 1915
I get an error message of data type mismatch in criteria expression.
Thanks.

Nov 13 '05 #2
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.

Nov 13 '05 #3
Thanks for your reply but I'm still getting Data type mismatch in
criteria expression error. I'm not an expert at writting this stuff
and with your assistance this is what I think you suggested?

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) = " & 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
Thanks for your help.

Nov 13 '05 #4
No, it's not what I suggested. Rather than just copying the code I gave you,
you modified your existing code so that you've got a blend of the two
methods.

You originally were using

WHERE tblEmployees.Em ployeeID = "A" OR tblEmployees.Em ployeeID = "B"

and I suggested changing it to

WHERE tblEmployees.Em ployeeID IN ("A", "B").

What you're getting instead is

WHERE tblEmployees.Em ployeeID IN (tblEmployees.E mployeeID = "A",
tblEmployees.Em ployeeID = "B")

The line of code

strTemp = strTemp & "((tblEmployees .EmployeeID) = " & Chr$(34) &
Me.ActiveContro l.ItemData(varI tem) & Chr$(34) & ", "

should be

strTemp = strTemp & Chr$(34) & Me.ActiveContro l.ItemData(varI tem) & Chr$(34)
& ", "
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

<Ly***********@ yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Thanks for your reply but I'm still getting Data type mismatch in
criteria expression error. I'm not an expert at writting this stuff
and with your assistance this is what I think you suggested?

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) = " & 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
Thanks for your help.

Nov 13 '05 #5
Works well, thanks for your help.

Lynn

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
4900
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours, Pujo
4
4679
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
3884
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
0
3792
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
8186
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
17882
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the problem is the charset? How I can avoid this warning? But the worst thing isn't the warning, but that the program doesn't work! The program execute all other operations well, but it don't print the converted letters: for example, in the string...
5
5773
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone know a good place to start looking for some theory on the subject of multi user applications? I know only bits and pieces, like about transactions, but a compendium of possible approches to multi user programming would be very appreciated!
17
10710
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when talking with another team -- codepage -- at the same time. I am more confused when I saw sometimes we need codepage parameter for wide character conversion, and sometimes we do not need for conversion. Here are two examples,
0
2332
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing Systems (MuCoCoS'08) Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08. <http://www.par.univie.ac.at/~pllana/mucocos08> *********************************************************************** Context
2
4662
by: Aussie Rules | last post by:
Hi, I have a site that Iwant to either display my text in english or french, based on the users prefernces ? I am new to webforms, but I know in winforms, this is pretty easy with a resource file. What is the best way to acheive this with webforms ?
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.