Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
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 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 13th, 2007, 03:52 AM
xoc xoc is offline
Registered User
 
Join Date: Apr 2007
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




 
Old April 15th, 2007, 03:35 PM
xoc xoc is offline
Registered User
 
Join Date: Apr 2007
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.






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





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