Solved

Access query SQL format into VB SQL format

Posted on 2007-03-26
8
1,265 Views
Last Modified: 2013-12-25
I want to copy a recordset to excel and the sql statement I'm using for the recordset is based on a query I already had made.  I thought I'd made all the necessary format changes between the SQL statement in the query and the VB code SQL statement but I can't get the VB code to run the sql statement and my best guess is that it is stumbling in the SELECT portion on the fields called Expr1 and Expr2 from the original query.  
Expr1 is getting multiple fields of info converted into 1 field for excel with spaces in between the info
Expr2 is an immediate if-then statement converting multiple descriptions into 2 part# types

the error message i've been consistently getting is "Run-time error '-214721908 (80040e0c)': Command text was not set for the command object."

Here is the code
partSQL = "SELECT tblItemDetail.[Damage Type], tblItemDetail.PO, tblItemDetail.[Supplier / Salvage / Junk], tblEnteredClaims.Pro, _

tblItemDetail!Qty & ‘ ‘ & tblParts!UM & ‘ ‘ & tblItemDetail![Part #] & ‘ ‘ & tblParts!Description AS Expr1, _

IIf([Damage Type]=’damage’,’88888K52’,IIf([Damage Type]=’concealed damage’,’88888K52’,IIf([Damage Type]=’empty_ carton’,’88888K52’,’88888K42’))) AS Expr2 _

FROM (tblEnteredClaims INNER JOIN tblItemDetail ON tblEnteredClaims.Pro = tblItemDetail.Pro) INNER JOIN tblParts ON_ tblItemDetail.[Part #] = tblParts.[Part #] _

Having (((tblEnteredClaims.Pro) = ‘” & ProIn & “’))"
0
Comment
Question by:efedora
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 20

Expert Comment

by:gatorvip
ID: 18795550
Did you leave the "group by" clause out on purpose?
0
 
LVL 1

Author Comment

by:efedora
ID: 18795744
Sorry I should have included that,
I did have this one in but I had tried removing it as part of troubleshooting here it is
GROUP BY tblItemDetail.[Damage Type], tblItemDetail.PO, tblItemDetail.[Supplier / Salvage / Junk], tblEnteredClaims.Pro, tblItemDetail!Qty, tblParts!UM, tblItemDetail![Part #], tblParts!Description, IIf([Damage Type]=’damage’,’88888K52’,IIf([Damage Type]=’concealed damage’,’88888K52’,IIf([Damage Type]=’empty carton’,’88888K52’,’88888K42’))) AS Expr2
0
 
LVL 20

Expert Comment

by:gatorvip
ID: 18796751
What is your exact code where you create&open the connection  and execute the SQL statement?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18797926
>>Command text was not set for the command object."<<
I would have to guess you are missing the line (or similar):
cmd.CommandText = partSQL
0
 
LVL 1

Author Comment

by:efedora
ID: 18799423
OK, I think I fixed the problem opening the RecordSet, I  tested it on a table instead of a SQL statement and that worked, I still included that code below. However when I plugged the SQL statement back in I recieved a new error message:
Run-time error ‘-2147217900 (80040e14)’:

Syntax error (missing operator) in query expression “IIf([Damage Type]=’damage’,’88888k52’,IIf([Damage Type]=’concealed damage’,’88888k52’,IIf([Damage Type]=’empty carton’,’88888k52’,’88888k42’)))’.

Code to open Record set:

'establishes the Part line recordset
Dim cnn2 As ADODB.Connection
Set cnn2 = CurrentProject.Connection
Dim PARTrs As New ADODB.Recordset
PARTrs.ActiveConnection = cnn2

'establishes Parts line sql statement
PARTrs.Open "SELECT....

'copies the part line record set to the spreadsheet
xlsh.Range("d3").CopyFromRecordset PARTrs






0
 
LVL 20

Accepted Solution

by:
gatorvip earned 500 total points
ID: 18799499
>>>
Syntax error (missing operator) in query expression “IIf([Damage Type]=’damage’,’88888k52’,IIf([Damage Type]=’concealed damage’,’88888k52’,IIf([Damage Type]=’empty carton’,’88888k52’,’88888k42’)))’.
<<<

I don't know if this is your actual code but the opening and closing quotes are different in what's pasted above.
0
 
LVL 1

Author Comment

by:efedora
ID: 18801189
Okay, after taking a fresh look at this whole problem I was able to get around the If-then statement issue that was causing the previous error message by creating a new table with the values I needed and then referencing that in the SQL
My problem now is with concatenating multiple fields into one field in order to copy it to excel.  
People have had similiar questions to this and I did what they were instructed to do but now I get no error message but it just not pasting the concatenated statement to excel and I don't know why.
here is the code:

(tblItemDetail.Qty + ' ' + tblParts.um + ' ' + tblItemDetail.[part #] + ' ' + tblParts.description) As partnote
0
 
LVL 1

Author Comment

by:efedora
ID: 18801980
I solved this one myself the + should be & and everything else stayed the same.  I'm using an ADO database and the people before me who asked a similar question were using DAO.  Thanks for the input on the question.  I appreciate it.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question