GW,
First, you question about the number of [br_code]s you need to deal with.
The easiest way to do that is to create a group by select query that returns
only the br_code. This should give you a record set that contains one
occurance of each br_code in your table. We will call that qselBrCodes.
Then you will need a query based on your table with one parameter which is
br_code. It should be layed out the way you want it to be in Excel. We will
call that qselBrData.
Here is the basic looping logic for that:
Set qdf = CurrentDb.QueryDefs("qselBrCodes")
Set rstBrCodes = qdf.OpenRecordset(dbOpenSnapshot, dbReadOnly)
'Be sure there are records to process
If rstBrCodes.Recordcount = 0 Then
MsgBox "No Data Found For This Report", vbInformation + vbOKOnly, _
"Data Error"
Exit Do
Else
rstBrCodes.MoveLast
rstBrCodes.MoveFirst
End If
Do While Not rstBrCodes.EOF
Set qdf = CurrentDb.QueryDefs("qselBrData")
qdf.Parameters(0) = rstBrCodes.[br_code]
Set rstBrData = qdf.OpenRecordset(dbOpenSnapshot, dbReadOnly)
If rstBrData.Recordcount > 0 Then
strXLFileName = "MyPathj" & rstBrCodes.[br_code] & ".xls"
DoCmd.TransferSpreadsheet acImport, 8, _
"qselBrData", strXLFileName, True
End If
rstBrData.Close
rstBrCodes.MoveNext
Loop
rstBrCodes.Close
set rstBrCodes = Nothing
set rstBrData = Nothing
set qdf = Nothing
Please be aware this is untested Air Code.
GW said:
Hi Ken,
I've to export the data one by one based on br_code value to respective .xls.
Query : Select * from CP where [br_code]="2803"
...........Select * from CP where [br_code]="3206"
one by one group
Below are required info..
tq so much.
DataType:
text|text|text|datetime|NumericDouble|text|NumericLonginteger|NumericDouble
FieldName:
name|acct_no|br_code|agrt_date|net_os|lawyer_code|app_age|app_gr_inc
Data:
CLARK|500000192290|2803|18/11/1997 0:00:00|-41.25|PAULC|39|0.00
JONATHAN|500000396191|3206|24/10/1997 0:00:00|0.00|LIMBP|32|0.00
MARTHA|500000709513|3302|2/3/1996 0:00:00|0.00|KADIR|38|0.00
LEX|502000145638|2803|16/5/2000 0:00:00|0.00|GANES|49|4500.00
LIONEL|504000186532|3301|7/3/2001 0:00:00|0.00|YAACO|34|1500.00
LANA|504000283954|3301|20/4/2001 0:00:00|0.00||31|2000.00
CHLOE|504001629429|3208|6/8/2003 0:00:00|0.00|||
LOIS|504001675332|3201|2/9/2003 0:00:00|0.00|HARIS|51|0.00
JASON|504001787879|2906|31/10/2003 0:00:00|21.50||56|26000.00
KALEL|502000150669|2806|20/5/2000 0:00:00|32.42|ROSNA|6|0.00
JOREL|504000379688|3206|8/6/2001 0:00:00|62.30|ARMAN|41|2617.50
KENT|504000704187|2905|27/12/2001 0:00:00|132.95|HARCH|15|0.00
GW|504000704217|2905|27/12/2001 0:00:00|132.95||15|0.00
KEN|505000000783|2905|22/12/2001 0:00:00|158.90|SOBRI|15|0.00
MARK|502000413887|3401|1/11/2000 0:00:00|222.00|FERN|46|2970.71
MIKE|504000978643|3201|13/6/2002 0:00:00|241.57||42|2717.00
:
Tell us more about the query and data structures so that we can suggest
meaningful examples. Also show us an example of the data records.
--
Ken Snell
<MS ACCESS MVP>
Hi experts,
Actually, appreciate if you could show me how write the code for the
problem
(the looping proces). I can create a query or a macro but what if there
are
thousand of
group of data in that particular fields and the data is not consistent eg
100...120,130...150,160...250. I want to export the data to excel based on
all group of data in that particular field at one time eg.
for 100 to 100.xls....250 to 250.xls.
pls guide me..
tq.
:
Ken,
Pardon my waxing nostalgic. Sort of sounds like "In my day we didn't
have
school buses, we had to walk to school in the snow and it was up hill
both
ways."
A quick Google search of the newsgroups will find many, 'nostalgic' posts
from people's experiences! I will spare everyone mine.... < g >