Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Access 2010 selective export

Posted on 2014-12-05
3
Medium Priority
?
173 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
[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
3 Comments
 
LVL 12

Accepted Solution

by:
pdebaets earned 1000 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 1000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

596 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