Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Array Solution

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LeAnn - 20 Sep 2005 00:55 GMT
I’m entering uncharted waters as far as my knowledge goes – especially with
arrays.

Here’s what I have:
Master Table (contains Master# and other info)
Member Table (contains foreign key = Master#, member# and received date)
Shipping Table (contains Master number and ship date)

Here’s what I need to do:

I need to create a coma delimited text file. The format needs to be:

Master#, MaxRecDate, member1, member 2, member 2……member 16

Each master has 16 members each with varying receive dates. The “Max Date”
above is the most recent date of the members.  I created a separate query
that gives me that piece.

However, the query I have for the export is vertical:
   Master 1,  member 1, date, loc
   Master 1,  member 2, date, loc
   .
   .
  Master 2, member 1, date, loc
  Master 2, member 2, date loc

The text file must contain only 1 line for each master #.  It will be based
on a ship date and will contain around 350 master #.   The way I envision the
solution is to create a recordset of the unique master #s and store them in
an array.  Then for each element in the array, create a recordset to get the
members and loop through it to create a coma delimited string variable and
print that variable to the text file. Somewhere along the line I’ll need to
grab the Max Date of the members to print with the master # and members.

I don’t understand arrays very well so I’m not sure if this make sense?  I’m
not sure if I have supplied enough information.

Thanks for any assistance!!!
LeAnn
LeAnn - 20 Sep 2005 02:15 GMT
Never mind, I found a different solution just looping through 2 different
recordsets.

Seems to work fine.  If any one is interested, I'll post my code.

> I’m entering uncharted waters as far as my knowledge goes – especially with
> arrays.
[quoted text clipped - 35 lines]
> Thanks for any assistance!!!
> LeAnn
GarryKhoo - 20 Sep 2005 10:53 GMT
Yes. would like to know what you did.

Signature

Thanks a lot.

Best Regards,
Garry Khoo

> Never mind, I found a different solution just looping through 2 different
> recordsets.
[quoted text clipped - 40 lines]
> > Thanks for any assistance!!!
> > LeAnn
Graham R Seach - 20 Sep 2005 14:10 GMT
LeAnn,

Rather than loop through the recordset, which will be slow, you might want
to take a look at the TransferText method, which will allow you to export
the contents of a query to many formats, include CSV. Just create a query
containing all the fields you want to export, then call the TransferText
method in VBA.

DoCmd.TransferText acExportDelim, , "qryMyQuery", "c:\Temp\myFile.csv",
False

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

> I'm entering uncharted waters as far as my knowledge goes - especially
> with
[quoted text clipped - 41 lines]
> Thanks for any assistance!!!
> LeAnn
LeAnn - 21 Sep 2005 01:07 GMT
Graham, thanks for you reply.  I did not know about that method.  However, I
don't think a query will be able to create the hoizontal format needed.  
Turns out also that they wanted different limitors between different pieces.  
Here was I came up with for a command button:

On Error GoTo ErrorHandler

'Set the environment and variables
Dim lngLFile As Long, strLFile As String
Dim db As DAO.Database, rst As DAO.Recordset, rst1 As DAO.Recordset
Dim varString As Variant
Dim strDate As String                                               'used to
format today's date to yyyymmdd format
Dim dteDate As Date                                                 'used to
get the youngest collection date for a pool
Dim lngRCnt As Long, lngCount                                       'count
how many pools in shipment, how many pools should be in text file
Dim strPool As String
Dim strDate1 As String                                              'used to
format the collection date to yyyyMMdd format

'Format today's date for client format
strDate = Format(Date, "yyyymmdd")

'Set database and recordset variables
Set db = CurrentDb()
Format

'Grouped query used to get the list of pools and the most recent date within
each pool
Set rst = db.OpenRecordset("SELECT * FROM qryPoolsByTAD WHERE ShipDate = #"
& Date & "#", dbOpenDynaset)

If rst.EOF = False And rst.BOF = False Then
rst.MoveLast
   
   'Create manifest text file
   lngLFile = FreeFile
   Open UDMANDIR & strDate & "_NG5874_NG5874_XXX_man" & ".txt" For Output
As lngLFile
   
   lngCount = rst.RecordCount              'how many pools should be in the
text files
   rst.MoveFirst
   lngRCnt = 0                             'initialize record count
   
   'Loop through rst recordset
   Do Until rst.EOF = True
       strPool = rst![tubeid]
       dteDate = rst![TAD]                 'TAD = Test after date for the
pool
       strDate1 = Format(Date, "yyyymmdd") 'format TAD for client
       
       'create a recordset of members for the each pool stored in rst
       Set rst1 = db.OpenRecordset("SELECT UnitID FROM tblConstits WHERE
TubeID = '" & strPool & "'")
       rst1.MoveLast
       If rst1.RecordCount <> 0 Then
           rst1.MoveFirst
           varString = ""
           Do Until rst1.EOF = True
              'create the string variable
              If varString = "" Then
                   varString = strPool & "," & strDate1 & "," & rst1![UnitID]
              Else
                   varString = varString & ";" & rst1![UnitID]
              End If
              rst1.MoveNext
           Loop
       End If
       
       'Write the information to the file and increment record counter
       Print #lngLFile, varString
       lngRCnt = lngRCnt + 1
       rst.MoveNext
   Loop
   Print #lngLFile, lngRCnt & " records listed."
Else
   MsgBox "There are no records to export for today.", vbOKOnly +
vbInformation, "No Records"
   GoTo Release_Objects
End If

MsgBox "Done." & Chr(10) & Chr(10) & "There were " & lngCount & " pools
ready for export and there were " & lngRnt & " records exported."

'Release objects from memory
Release_Objects:
   rst.Close
   db.Close
   Set rst = Nothing
   Set rst1 = Nothing
   Set db = Nothing
   Close
   Reset

Exit_Sub:
   Exit Sub
   
ErrorHandler:
   MsgBox "Error #" & Err.Number & " - Description: " & Err.Description,
vbOKOnly + vbExclamation, "Error"
   Resume Release_Objects

> LeAnn,
>
[quoted text clipped - 58 lines]
> > Thanks for any assistance!!!
> > LeAnn
Graham R Seach - 25 Sep 2005 13:07 GMT
LeAnn,

I didn't spend a lot of time on this, but the following query should return
the values you want. The problem is the semicolon separating each record.
I'm not sure how you'd do that using TransferText.

Either way, you'll only need a single recordset.

SELECT Q1.TubeID & "," & Format(Date, "yyyymmdd") & "," & Q1.UnitID
FROM qryPoolsByTAD As Q1
INNER JOIN tblConstits As Q2 ON Q2.TubeID = Q1.TubeID
WHERE Q1.ShipDate = Date()

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------

> Graham, thanks for you reply.  I did not know about that method.  However,
> I
[quoted text clipped - 182 lines]
>> > Thanks for any assistance!!!
>> > LeAnn
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.