LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default using ado to query the contents of a spreadsheet

Greetings,

I am trying to access an excel spreadsheet using ado and one of the
fields have a zipcode in it. There is a number of tabs or worksheets in
this workbook and I am seeing some strange results that I need some help on.


In some instances the column in question for the zipcode has 10
characters or 5 characters (i.e. xxxxx-xxxx or xxxxx). On one worksheet
when I look at the datasource it shows up as null for a zipcode entered
in as xxxxx-xxxx, and then another worksheet it will show up perfectly fine.

This is the query I am using

"SELECT * FROM [" & aStateNames(iStateLoop) & "$]

where aStateNames refers to the name of the worksheets.




And this is the way I am calling the query

Function DbQuery(strSql As String, strFile As String, Optional
bolConnect As Boolean = False) As Variant

'Handle any errors found
On Error GoTo ErrorHandler
'Local variables
Dim objAdoRs As ADODB.Recordset
Dim strConn As String
'Create the reference to the ado recordset
Set objAdoRs = New ADODB.Recordset
'Ado recordset object
With objAdoRs
'SEt the object properties
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockBatchOptimistic
'Set the connection string
If Not bolConnect Then
strConn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ="
& strFile
Else
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFile & ";" & _
"Extended Properties=""Excel 8.0;HDR=No"""
End If
'Open the recordset
.Open strSql, strConn
'.Save "c:\testjrd.xml", adPersistXML

'Check to see if the recordset brought back a list of records
If Not .EOF And Not .BOF Then
'Return the recordset as a 2D array
DbQuery = .GetRows
Else
'Nothing was found, so return nothing
DbQuery = ""
End If
End With
'Free the object
Set objAdoRs = Nothing
ExitFunc:
'Exit the function
Exit Function
ErrorHandler:
'Print out the error
Debug.Print strSql + " " + Err.Description + " " + _
Err.Source, vbCritical, "Import"
Err.Clear
Resume ExitFunc
End Function


Does any one have any idea on what is causing this weird behaviour and
what the solution could be to resolve it.
 
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
Import New Database Query (Union Query) in Spreadsheet klock Excel Discussion (Misc queries) 2 September 24th 09 01:30 AM
Excel cell contents to query criteria Jimbo Excel Discussion (Misc queries) 1 April 22nd 09 07:46 PM
How do I use the ActiveCell's contents as a string for a web query thebird[_2_] Excel Programming 1 June 22nd 05 07:13 AM
Web query - using cell contents as part of URL claytorm[_2_] Excel Programming 1 July 29th 04 04:16 PM
CONTENTS OF TEXTBOX TO BE THE CRITERIA ON A DATABASE QUERY AQM Excel Programming 6 May 28th 04 02:18 PM


All times are GMT +1. The time now is 01:13 AM.

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"