?
Solved

strCriteria

Posted on 2007-11-15
2
Medium Priority
?
419 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 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

762 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