Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Duplicate Project in VBE

The following code works well. It uses the ADO object to
draw data from a workbook and place it in another.
Everything is great except this: when the routine is
completed, a copy of the original workbook is placed in
the VBE (I can see it in the explorer window!). The only
way to close it is to close Excel and restart. I thought
that closing the recordset would stop this, but it does
not.

Note: I have significantly abridged the code for
readability - I don't think I am missing any of the key
components, however.

Public Function RunQuery(Sql As String, ConnString As
String, Optional ShtName As String = "Query Result", _
Optional QueryString As String, Optional StartDate As
Date, Optional EndDate As Date) As Workbook

Dim Wkb As Workbook, Wks As Worksheet
Dim x As Integer

Set RS = New ADODB.Recordset
' Open the recordset
RS.Open Sql, ConnString, adOpenForwardOnly,
adLockReadOnly, adCmdText

' In case no records are returned
If RS.EOF Then
MsgBox GLOBALS.msgNORECORDS & vbCrLf &
QueryString, vbExclamation, AppName
RS.Close: Set RS = Nothing
Exit Function
End If

Application.ScreenUpdating = False ' Turn off
screenupdating for faster run
Set Wkb = Workbooks.Add: Set Wks = ActiveSheet

With Wks
.Range("A2").CopyFromRecordset RS
.Name = ShtName
End With

Set RunQuery = Wkb
RS.Close ' Close the recordset - IS THIS THE PROBLEM?
Application.ScreenUpdating = True
' Release object variables
Set Wkb = Nothing: Set Wks = Nothing: Set RS = Nothing
Exit Function

Thanks!

Seth
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excell error "Can't find Project or Library" Project VBAProject Lost in Excel Excel Worksheet Functions 0 April 12th 07 04:42 PM
How do you delete duplicate addresses, but keep duplicate names? Shelly Excel Discussion (Misc queries) 1 August 28th 06 10:36 PM
How to convert MS Project to MS Excel. I don't have MS Project. Jane Excel Discussion (Misc queries) 1 February 20th 06 10:01 PM
Need a project. bach New Users to Excel 6 August 30th 05 09:47 AM
I pay $ for this project Fred Grange Charts and Charting in Excel 0 December 28th 04 12:41 PM


All times are GMT +1. The time now is 01:07 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"