0

I got this code:

 SQLQ = "SELECT * FROM blabla WHERE bsn = '" &
 Format(ThisWorkbook.Sheets("QueryResult").Range("B1").Value,
 "#########000000000") & "' AND datum= '#" &
 ThisWorkbook.Sheets("Initiële berekening").Range("C6").Value & "#'"
     Debug.Print SQLQ
     objRs.Open SQLQ, con, adOpenStatic

When I run this I get an error from VBA. "Data type mismatch in criteria expression" (Error -2147217913(80040e07))

With the debug.print I check if it gets the right values and it does so I don't get what I do wrong..

1
  • 1
    Try to remove the single quotes around the date (next to the #). Commented Nov 28, 2016 at 8:09

1 Answer 1

1

You will also need to format the date expression:

 SQLQ = "SELECT * FROM blabla WHERE bsn = '" &
 Format(ThisWorkbook.Sheets("QueryResult").Range("B1").Value, "#########000000000") & "' AND datum= #" &
 Format(ThisWorkbook.Sheets("Initiële berekening").Range("C6").Value, "yyyy\/mm\/dd") & "#"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.