Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 June 7th, 2011, 02:26 AM
Registered User
 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default variables in SQL string-building problem

I'm getting a very peculiar result when using string variables to build an SQL string to retrieve a recordset from a spreadsheet....

If I use a variable or activesheet.name then I get a "Not a valid name " error, now if I hard code the active sheet's name ie. "X103878$" it works fine and returns the record set OK.

I've declared the variable beforehand as a string I've even tried it as a variant.

code

sqlstring = "SELECT * FROM [" & Ref & "$] " & _
"WHERE [" & Ref & "$!customer]='" & Customer & "'"

PreferencedRows.Open sqlstring, adodbConnection, adOpenDynamic, adLockOptimistic

/code

The problem occurs with the "Ref" variable, if I assign a literal string to it, the code is fine, but if I assign activesheet.name to it, the code doesn't work, even though the names are identical ??
Any help would be appreciated, thanks in advance.
PS our company doesn't use Access and I have read-only authorisation on the main company database so I use Excel as a local data source, it makes my life easier(ish)





Similar Threads
Thread Thread Starter Forum Replies Last Post
building string one char at a time bkelly C++ Programming 0 October 24th, 2010 09:26 PM
Building and passing Environment variables Durkee VB.NET 2002/2003 Basics 0 November 7th, 2007 04:25 PM
Urgent: Building a java object from XML String,XSD neetukk XML 1 January 5th, 2007 02:19 PM
Problem with SQL SERVER Connection String Non Linear BOOK: Beginning ASP 3.0 3 October 20th, 2005 12:35 AM
Chapter 8 Building a SQL String kimch BOOK: Beginning Access VBA 0 June 7th, 2005 03:45 PM





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