[AccessD] A2003: Merging top 50 files then next 50 files andsoon

Darren D darren at activebilling.com.au
Tue Aug 5 00:22:00 CDT 2008


Stuart - Fantastic

Works an absolute treat many many thanks - you are a legend

What is the standard code bits to get it to release the file whilst the dB is
open? I also assume there are objects to be closed or set to nothing - yes?

Code working nicely below

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub ps_CopyBlocks()

On Error Resume Next

Dim lngCounter As Long
Dim lngFileCounter As Long
Dim strFile As String
Dim strMergeFile As String

strMergeFile = "MergeFile00.txt"
Open strMergeFile For Output As #1
strFile = Dir$("*.xml")
Do
    Open strFile For Input As #2
    While Not EOF(2)
        Line Input #2, strtemp
        Print #1, strtemp
    Wend
    Close #2
    lngCounter = lngCounter + 1
           If lngCounter = 10 Then
        lngFileCounter = lngFileCounter + 1
                lngCounter = 0
        Close #1
strMergeFile = "MergeFile" & Format(lngFileCounter, "00" & ".txt")
        Open strMergeFile For Output As #1
           End If
          strFile = Dir$
Loop Until strFile = ""

End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
Darren

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Tuesday, 5 August 2008 2:55 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] A2003: Merging top 50 files then next 50 files andsoon

I made at least one error :-)

strMergeFile = "MergeFile" & Format(lngCounter,"00")
should be
strMergeFile = "MergeFile" & Format(lngFileCounter,"00")

(lngCounter is used to count the original files in the directory, lngFileCounter
is used to 
name the MergeFiles automatically)

Now you should get (unless there are other bugs):

Files 1 - 50 in MergeFile01
Files 51-100 in MergeFile02
Files101-150 in MergeFile03 etc.



On 5 Aug 2008 at 14:17, Darren D wrote:

> Hi Rocky and Stuart
> 
> Stuart I have copied and pasted the code below
> Maybe air code but it's beyond my limited understanding :-)
> I ran it and it errored I have forced it to resume on error
> I can see an output file ending in 00 but I can't delete it whilst the dB is
> open
> I can also see an output file ending in 01 with some of the xml in it
> What happens if there is more that 50 XML Should it create a new 02 file? 
> Way beyond me - Sorry
> 
> Many many thanks
> 
> Darren
> 
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
> Sent: Tuesday, 5 August 2008 11:35 AM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] A2003: Merging top 50 files then next 50 files and soon
> 
> Something like this? (Aircode so will probably need a fair of
checking/cleaning
> up)
> 
> Dim lngCounter as Long
> Dim lngFileCounter as Long
> Dim strFile as String
> DIm strMergeFile as String
> 
> strMergeFile = "MergeFile01"
> open strMergeFile for Output as #1
> strFile = Dir$("*.*")
> Do
> open strFile for Input as #2
> While not eof(2)
> line input #2, strtemp
> Print #1, strtemp
> Wend
> close #2
> lngCOunter = lngCounter + 1
> if lngCounter = 50 then
> lngFileCounter = lngFileCounter +1
> lngCounter = 0
> close #1
> strMergeFile = "MergeFile" & Format(lngCounter,"00")
> open strMergeFile for Output as #1
> end if
> strFile = Dir$
> Loop until strFile =""

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list