Solved

strCriteria

Posted on 2007-11-15
2
410 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

726 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