Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 July 12th, 2006, 10:53 AM
Registered User
 
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to am6019a
Default code to make a list, anyone see what is wrong?

I am trying to use data from one workbook to make a list in another workbook. Basically if the file "c:\filepath\DataFromFirstWorkBook.xls" exists, the it should past info into the second workbook. Here is the code

Code:
Sub creatingalist()
    Dim QuoteID As Variant
    Dim i As Integer
    i = 1
    With Application.FileSearch
    Do Until 1 = 1231
    QuoteID = Workbooks("WorkBook1.xls").Worksheets("Fid Data").Cells(i, 9).Value
    .LookIn = Dir("c:\FilePath" & QuoteID)
    If .Execute > 0 Then Workbooks("WorkBook!.xls").Worksheets("Fid Data").Cells(i, 9).Copy Destination:=Workbooks("Fiducuary Submissions.xls").Worksheets("Fid Data").Cells(i, 1)
    i = i + 1
    Loop
    End With

End Sub
 
Old July 12th, 2006, 02:03 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Indentation, formatting and line continuation sure would make it easier to see what is going on,
and to maintain what you have. For example:
Code:
Sub creatingalist()

    Dim QuoteID As Variant
    Dim i As Integer

    i = 1
    With Application.FileSearch
        Do Until 1 = 1231   ' I presume you mean i = 1231 rather than 1 = 1231 . . .
            QuoteID = Workbooks("WorkBook1.xls").Worksheets("Fid Data").Cells(i, 9).Value
            .LookIn = Dir("c:\FilePath" & QuoteID)
            If .Execute > 0 Then _
                Workbooks("WorkBook1.xls").Worksheets("Fid Data").Cells(i, 9).Copy _
                Destination:=Workbooks("Fiducuary Submissions.xls").Worksheets("Fid Data").Cells(i, 1)
            i = i + 1
        Loop
    End With

End Sub
Also, I think an easier looping construct would be:
Code:
Sub creatingalist()

    Dim QuoteID As Variant
    Dim i As Integer

    With Application.FileSearch
        For i = 1 To 1231
            QuoteID = Workbooks("WorkBook1.xls").Worksheets("Fid Data").Cells(i, 9).Value
            .LookIn = Dir("c:\FilePath" & QuoteID)
            If .Execute > 0 Then _
                Workbooks("WorkBook1.xls").Worksheets("Fid Data").Cells(i, 9).Copy _
                Destination:=Workbooks("Fiducuary Submissions.xls").Worksheets("Fid Data").Cells(i, 1)
        Next i
    End With

End Sub
Did you mean to have
Code:
    ...
    .LookIn = Dir("c:\FilePath\" & QuoteID)
    ...
    instead of
Code:
    ...
Code:
    .LookIn = Dir("c:\FilePath" & QuoteID)
    ...?
    What result is it that you are getting?
Does the code raise an error, or just run without generating results?
 
Old July 13th, 2006, 09:12 AM
Registered User
 
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to am6019a
Default

Brian,
Thanks for you help so far. Right now it isn't generating results.

 
Old July 13th, 2006, 10:30 AM
Registered User
 
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to am6019a
Default

Brian,
got it to work, thanks again






Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with my code? DyerOppenheimer BOOK: Beginning Ajax with ASP.NET 0 January 7th, 2008 08:46 AM
What's wrong with this code? AlDugan XSLT 3 May 19th, 2006 12:06 PM
Can anyone tell me what's wrong with this code? hobgoblin BOOK: Beginning ASP 3.0 0 March 3rd, 2005 01:47 PM
What Wrong Of My Code ck C++ Programming 0 January 27th, 2005 08:35 AM
CHPT 17.Wrong succession list 5 last added sites. RABARBAR BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 5th, 2004 06:11 PM





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