Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2007, 10:22 AM
Registered User
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel VBA & SQL

I'm using Excel VBA to run a SQL query, put the results in a seperate worksheet and then after that run a find and replace on a specific column.

If I run this through the find and replace doesn't happen. However if I put a break point on the coding and F8 through the find and replace works.
it's as if the F&R is working before the SQL query has finished. I've put wait commands in and that's not solved it.

I hope somebody could help me on this please.

Thanks
 
Old April 5th, 2007, 11:09 AM
Authorized User
 
Join Date: Sep 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Make sure your BackgroundQuery is set to False



With ActiveSheet.QueryTables.Add( _
        Connection:=sConn, _
        Destination:=ResultLocation, _
        Sql:=sSql)

        .RefreshStyle = xlOverwriteCells 'Over-write the existing data from previous queries
        .AdjustColumnWidth = False 'Prevents the query from adjusting the column width every time it runs
        .RefreshOnFileOpen = False 'Shutsdown the automatic refresh function
        '.FieldNames = False 'Hides the column headers that come from the query
        .Refresh BackgroundQuery:=False 'Actually sends this query, the background false options prevents the program from continuing until the refresh is complete

End With
 
Old April 5th, 2007, 01:28 PM
Registered User
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perfect!! - thank you very much






Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VBA copy & paste wensmail Excel VBA 1 September 17th, 2007 11:13 PM
VBA Code to read the structure & data of an excel alam1 Excel VBA 0 April 24th, 2007 11:39 PM
How can use sql syntax in excel vba Biggladius Excel VBA 4 October 6th, 2004 04:15 AM
Which Book for VBA/Access/SQL/Excel? rmg VB Databases Basics 0 July 29th, 2004 03:19 PM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.