Combined WhereCondition Using Access2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emari2
    New Member
    • Oct 2008
    • 2

    #1

    Combined WhereCondition Using Access2007

    I need a complex query from a table
    The first part alone works well
    Code:
        Dim fechainicial As Date
        Dim stDocName As String
        Dim stLinkCriteria As String
    fechainicial = Text207
    fechafinal = Text209
        stDocName = "Incidenciasenlabasededatos"
        stLinkCriteria = "[Fecha]>=#" & fechainicial & "#" & " And " & "[Fecha]<=#" & fechafinal & "#"
          
        DoCmd.OpenForm stDocName, , , stLinkCriteria
    The second alone works well
    Code:
     If Texto167 = "Técnica" Then
        
        stLinkCriteria = "[Tipo de incidencia]='Técnica'"
       
        End If
    but if I joint the two, does not work and I have I sintax error

    Code:
     stLinkCriteria = stLinkCriteria & " And " & "[Tipo de incidencia]='Técnica'"
    or
    
     stLinkCriteria = [B]stLinkCriteria[/B] & " Where " & "[Tipo de incidencia]='Técnica'"
        MsgBox (stLinkCriteria)
    Note.- in this case stLinkCriteria is the first one of course
    I am missing something in the sintax . Can you help? Thanks
    Last edited by Stewart Ross; Oct 20 '08, 08:52 AM. Reason: Please use the code tags provided.
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    You do *not* use the word "WHERE" in a WhereCondition argument! Just use another AND.

    Comment

    • emari2
      New Member
      • Oct 2008
      • 2

      #3
      Originally posted by RuralGuy
      You do *not* use the word "WHERE" in a WhereCondition argument! Just use another AND.
      I already use another AND and something is wrong with the sintax as it gives me an error

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Hi. It seems to me that you've not thought through what will happen if the IF statement does not match the contents of Texto167. Since stLinkCriteria will be left as an empty string, the value of stLinkCriteria will then just become

        Code:
        stLinkCriteria = <empty string> & <your new criteria> 
        =>
        " AND [Tipo de incidencia]='Técnica'"
        which is bound to generate an error.

        Simplest solution is to move the AND to the end of the part within the IF:

        Code:
        stLinkCriteria = "[Tipo de incidencia]='Técnica' AND "
        -Stewart

        Comment

        Working...