Consulting

Results 1 to 2 of 2

Thread: VBA Syntax to run sql statement with where and order by

  1. #1
    VBAX Tutor jo15765's Avatar
    Joined
    Oct 2011
    Posts
    281
    Location

    VBA Syntax to run sql statement with where and order by

    I know how to connect to sql server and run a query. But for the life of me, I can not get the syntax correct for this statement. WHAT do I keep inputting incorrect?

    [vba]
    strsql = "Select name from names where bday between "&A1&" AND "&A2&" Order BY name ASC"
    [/vba]
    Go to Heaven for the climate, Hell for the company.
    ~~Mark Twain

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    try this:
        strsql = "Select name from names where bday between " & Range("A1") & _
                 " AND " & Range("A2") & " Order BY name ASC"

Posting Permissions

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