p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 13th, 2007, 04:52 AM
xoc xoc is offline
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel ADO 2.7 problem subindex out of interval

Hi all,

I'm new to this forum and almost new to VB. I will be very grateful if you can bring some help with a problem I am experiencing.

I'm trying to get data from one excel spreadshhet into another by using ADO. I run my macro from a sheet named "Captura" in a given workbook, and it should copy some data from a sheet called "Data" in a file named "rex-2007.xls" located in another computer ("Server").

The first time I run the macro, I get the error

"Subíndice fuera del intervalo"

(spanish version of excel; literal translation: Subindex out of interval/range)

If at the VB dialog box I choose to debug, the following code line is yellow highlighted:

    ActiveWorkbook.Worksheets("captura").Cells(6, 1).CopyFromRecordset rst

(remaining code at the end of the post)

At this point, the source file rex-2007.xls remains open in my computer. If, without closing the source file, I run the macro again from the destination worksheet, it runs properly and I get the data. If I close the source file and try the macro again, I encounter the same error and situation.

Again, I will be very grateful for any insight about this problem.


My code is the following (some processing lines at the end have been comented to speed testing):

Sub getrecordsbyado()

' Microsoft ADO 2.7

    Application.Goto Reference:="captura_borrar"
    Selection.ClearContents

    Dim cnt As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim strDB As String
    Dim strCommand As String
    Dim recCount As Long

    strDB = "\\server\data\2007\rex-2007.xls"

    cnt.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & strDB & ";Extended Properties=Excel 8.0;"

    strCommand = "SELECT data, solicitante,mostra,sai FROM [dat$] WHERE MS=""X"""

    rst.Open strCommand, cnt

    ActiveWorkbook.Worksheets("captura").Cells(6, 1).CopyFromRecordset rst

    rst.Close
    cnt.Close
    Set rst = Nothing
    Set cnt = Nothing


  ' Application.Goto Reference:="captura_col1"
   ' Selection.FormulaArray = "=VALUE(LEFT(RC[5],4))"
    'Selection.Copy
    'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    ' :=False, Transpose:=False
    'Application.Goto Reference:="captura_col2"
    'Selection.FormulaR1C1 = "=VALUE(RIGHT(RC[4],5))"
    'Selection.Copy
    'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
     ' :=False, Transpose:=False
    'Application.Goto Reference:="captura_trim"
    'Selection.ClearContents


End Sub




Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old April 15th, 2007, 04:35 PM
xoc xoc is offline
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry...

I think I was a bit confused when posting this topic, and I failed to locate the most adequate forum. I have now opened a post regarding this same problem on the MS Office/Excel VBA forum. Moderator, please feel free to delete the topic from the VB/Beginning VB 6 forum if you find it appropiate. I want to apologize for the inconveniences caused.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to Access using ADO JezLisle Excel VBA 2 July 22nd, 2007 06:55 PM
Problem getting Excel data with ADO 2.7 xoc Excel VBA 2 April 18th, 2007 10:37 AM
Using ADO to Query Excel alex_w Excel VBA 1 October 19th, 2006 05:42 AM
ado excel/access loane Excel VBA 5 August 17th, 2004 11:18 AM
A date interval with a date interval query spinto SQL Server 2000 7 May 15th, 2004 05:26 AM



All times are GMT -4. The time now is 04:17 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc