String Concatination Error

T

Toco Hara

I have error in SQL expression when when my form opens. I
think problem is I have a composite key. The PK is
CustomerNum and DtOrder. I try to concatinate the PK, but
I don't think my syntax is correct. Here is my strSQL:

Dim strSQL As String, strCustID as String, strDtOrder As
String,

strCustID = Forms!frmCustomerData.CustomerID
strDtOrder = Forms!frmCustomerData.DtOrder
strSQL = "SELECT CallDt,CallTime,Disposition FROM
tblOrderHistory WHERE "
strSQL = strSQL & "CustomerID='" & strCustomerID & "' And
DtOrder='" & "#" & DtOrder & "#" & "'"
strSQL = strSQL & "' ORDER BY CallDt ASC,CallTime ASC,
Disposition ASC;"
Set rsOne = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)

Can someone show me my error? I can not concatinate the
PK because it is a composite key. Thank you

Toco
 
M

Matt Williamson

Toco-

I always debug.print long SQL strings like that just to see what access
sees. Often times, it's just a missed quote somewhere that throws everything
off.

Take the output from your debug and enter it as a new sql query, that will
usually tell you what is wrong if it's not obvious by looking at it.

HTH

Matt
 
T

Treebeard

It looks like you have extra quotes around DtOrder
DtOrder= #" & DtOrder & "#"

Although I always use the formats statement with dates, although I'm not
sure if it's necessary.
DtOrder= #" & Format$(DtOrder , "mm/dd/yyyy") & "#"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top