Solved

strCriteria

Posted on 2007-11-15
2
411 Views
Last Modified: 2012-05-05
I use a pop-up form that dynamically generates a query which is used as rowsource for another form.

This pop-up form uses ID number to filter for the records.   This process works great (see SQL between &&&&s).

Now, I need to use the same concept for another pop-form.  In this case, however, I'm want to use a text string that needs to be added to the query criteria.   For the SQL (between ****s), I added additional double-quotes to the strCriteria variable.   Unfortunately, the query is not created when executing the SQL.  

What's missing in the SQL (between *******s) so that it accepts text string in field [UserCreated]?

Thanks,
EEH


&&&&&&  Works great when adding NUMBER data type to query criteria (such as "In") &&&&&&

'Loop through selected items in the list box and build text string
If Me!lstCTM.ItemsSelected.Count > 0 Then
    For Each varItem In Me!lstCTM.ItemsSelected
        If Len(strCriteria) > 0 Then
            strCriteria = strCriteria & ", "
        End If
        strCriteria = strCriteria & Me!lstCTM.ItemData(varItem)
    Next varItem
    strCriteria = "[tblCTM].TrackNoIDpk IN (" & strCriteria & ")"
Else
    strCriteria = "[tblCTM].TrackNoIDpk Like '*'"
End If                                    
                 
strSQL = "SELECT tblCTM.TrackNoIDpk, tblCTM.ClonedTrackNoIDpk, tblCTM.PARIDfk, tblCTM.CollectionAnalysis, tblCTM.CTM, tblCTM.CTMSublevel, " & _
         "tblCTM.Source, tblCTM.WorkingGroup, tblCTM.Observation, tblCTM.Discussion, tblCTM.Recommendation, tblCTM.DateCreated, tblCTM.UserCreated, tblCTM.DateModified, tblCTM.UserModified, tblCTM.ReportDate FROM tblCTM " & _
         "WHERE " & strCriteria & ";"

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&         
         
 

******* Attempted to use above concept to add text data type to query criteria (such as 'joe.schmo', 'jane.doe') **************
 
'Loop through selected items in the list box and build text string
If Me!lstUser.ItemsSelected.Count > 0 Then
    For Each varItem In Me!lstUser.ItemsSelected
        If Len(strCriteria) > 0 Then
            strCriteria = strCriteria & ", "
        End If
        strCriteria = strCriteria & Me!lstUser.ItemData(varItem)
    Next varItem
    strCriteria = "[tblCTM].UserCreated """ & strCriteria & """"
Else
    strCriteria = "[tblCTM].UserCreated Like '*'"
End If                                    
                 
strSQL = "SELECT tblCTM.TrackNoIDpk, tblCTM.ClonedTrackNoIDpk, tblCTM.PARIDfk, tblCTM.CollectionAnalysis, tblCTM.CTM, tblCTM.CTMSublevel, " & _
         "tblCTM.Source, tblCTM.WorkingGroup, tblCTM.Observation, tblCTM.Discussion, tblCTM.Recommendation, tblCTM.DateCreated, tblCTM.UserCreated, tblCTM.DateModified, tblCTM.UserModified, tblCTM.ReportDate FROM tblCTM " & _
         "WHERE """ & strCriteria & """;"

********************************
0
Comment
Question by:ExpExchHelp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 20289043
for text data you have to enclosed each item with a single  quote (chr(39))

strCriteria = strCriteria & chr(39) & Me!lstUser.ItemData(varItem) & chr(39)
0
 

Author Comment

by:ExpExchHelp
ID: 20289238
Perfect... thanks for providing me this feedback.

EEH
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question