Results 1 to 4 of 4

Thread: [RESOLVED] Select with multiple conditions

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Resolved [RESOLVED] Select with multiple conditions

    I have some code where this works fine

    Code:
    With rs
        .Open "SELECT * FROM Requests where RequestType = '" & Cells(Target.Row, 1) & "'", cn, adOpenKeyset, adLockOptimistic, adCmdText
        
        .Fields("Status").Value = Cells(Target.Row, 4).Value
        .Fields("Notes").Value = Cells(Target.Row, 6).Value
        .Update
    End With
    I'm trying to add a second condition and the syntax is wrong. What's my mistake?

    Code:
    .Open "SELECT * FROM Requests where RequestType = '" & Cells(Target.Row, 1) & "' AND DateCreated = '" & cells(target.Row, 2) & "'", cn, adOpenKeyset, adLockOptimistic, adCmdText

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Select with multiple conditions

    dates should be enclosed in # rather than '

    also date formats are critical (mm/dd/yy) it may be 4 digit year, i am not sure on that
    Last edited by westconn1; Apr 8th, 2013 at 04:25 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Select with multiple conditions

    Thanks but it's a syntax error not a wrong result and in any case this (where I've just duplicated the working part) isn't correct either


    .Open "SELECT * FROM Requests where RequestType = '" & Cells(Target.Row, 1) & "' AND RequestType = '" & cells(target.Row, 1) & "'", cn, adOpenKeyset, adCmdText"

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width