Solved

Access 2010 selective export

Posted on 2014-12-05
3
167 Views
Last Modified: 2014-12-05
Access 2010

I found code to do what I want but it does not work.  The code is:

[embed=snippet 8267437]Dim nLowKey As Integer
Dim nHighKey As Integer
Dim sKey As String
nLowKey = txtLowKey
nHighKey = txtHighKey
sKey = "HOLDER"
Dim qry As QueryDef
Dim sqlStmt As String
sqlStmt = "SELECT * FROM CARDS WHERE (" & sKey & " = " & nLowKey & ") OR (" & sKey & " = " & nHighKey & ");"
Set qry = CurrentDb().QueryDefs("qryTemp")
qry.SQL = sqlStmt
DoCmd.TransferText acExportDelim, "ExportCards", qry.Name, "D:\IBMCollection\Cards.csv"

Open in new window



It goes fine until the Set qry statement.  Then I get a Run-time 3265 Item not found in this collection

Where is qryTemp defined?  
In the DoCmd where is qry.Name defined?
Dim nLowKey As Integer
Dim nHighKey As Integer
Dim sKey As String
nLowKey = txtLowKey
nHighKey = txtHighKey
sKey = "HOLDER"
Dim qry As QueryDef
Dim sqlStmt As String
sqlStmt = "SELECT * FROM CARDS WHERE (" & sKey & " = " & nLowKey & ") OR (" & sKey & " = " & nHighKey & ");"
Set qry = CurrentDb().QueryDefs("qryTemp")
qry.SQL = sqlStmt
DoCmd.TransferText acExportDelim, "ExportCards", qry.Name, "D:\IBMCollection\Cards.csv"

Open in new window

0
Comment
Question by:IBMJunkman
3 Comments
 
LVL 12

Accepted Solution

by:
pdebaets earned 250 total points
ID: 40484140
Just create a query named "qryTemp". Put any old SQL statement in it. The SQL within will be replaced by the code you posted above.
0
 
LVL 26

Assisted Solution

by:Nick67
Nick67 earned 250 total points
ID: 40484143
If you create a dummy saved query named qryTemp with "Select 1 as stuff" your cose would then work.  You are overwriting the SQL of an EXISTING query.  If it doesn't exist, well BANG! is the result.
0
 

Author Closing Comment

by:IBMJunkman
ID: 40484146
It worked!  The overwriting was mentioned but the fact it was an existing query escaped me.  Many thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

791 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