Solved

strCriteria

Posted on 2007-11-15
2
403 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
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now