NeverTooLate
New member
- Local time
- Today, 10:34
- Joined
- Nov 11, 2009
- Messages
- 6
Hi there!
I'm writing a recordset to a table (ready for export to SAP) which has 2 sources of data (queries). I need to sort the recordset then add a sequential Item Number.
My 2 problems are, when I sort the recordset, it sorts each source separately - I need them to be sorted together.
My second problem is the sequential number. The recordset holds vehicle service information. There are many vehicles, each with many services and many items in each service. The sequential numbers are for the items in a service, start at 10 and increase by 10. So:
Vehicle 1 - Service 1 - Item 1 - 10
Item 2 - 20
Item 3 - 30
Service 2 - Item 1 - 10
Item 2 - 20
Item 3 - 30
and so on.
If I can get the sort to work I was thinking of moving to the first record and setting a variable to be the service number of that record. Then add sequential numbers until that service number changes. Then reset the variable to the now current service number and restart the counter.
Will this work?? Is a bookmark the right way to set the variable?
The below code is part of a function that creates 3 table so I'll only paste the relvant code for this table creation.
Thanks for your help.
I'm writing a recordset to a table (ready for export to SAP) which has 2 sources of data (queries). I need to sort the recordset then add a sequential Item Number.
My 2 problems are, when I sort the recordset, it sorts each source separately - I need them to be sorted together.
My second problem is the sequential number. The recordset holds vehicle service information. There are many vehicles, each with many services and many items in each service. The sequential numbers are for the items in a service, start at 10 and increase by 10. So:
Vehicle 1 - Service 1 - Item 1 - 10
Item 2 - 20
Item 3 - 30
Service 2 - Item 1 - 10
Item 2 - 20
Item 3 - 30
and so on.
If I can get the sort to work I was thinking of moving to the first record and setting a variable to be the service number of that record. Then add sequential numbers until that service number changes. Then reset the variable to the now current service number and restart the counter.
Will this work?? Is a bookmark the right way to set the variable?
The below code is part of a function that creates 3 table so I'll only paste the relvant code for this table creation.
Code:
Function Create_PPS_WINPAQ_Table()
Dim db As Database
Dim source As Recordset
Dim source2 As Recordset
Dim source3 As Recordset
Dim dest As Recordset
Dim dest2 As Recordset
Dim dest3 As Recordset
Dim dest4 As Recordset
DoCmd.SetWarnings False
DoCmd.OpenQuery "qry_Cleanup_tbl_PPSservCodes"
DoCmd.OpenQuery "qry_Cleanup_tbl_PPSservOps"
DoCmd.OpenQuery "qry_Cleanup_tbl_CommonServTempl"
DoCmd.SetWarnings True
Set db = CurrentDb()
Set source = db.OpenRecordset("qry_PPSservCodes")
Set dest = db.OpenRecordset("tbl_PPSservCodes")
Set source2 = db.OpenRecordset("qry_PPSservOps")
Set dest2 = db.OpenRecordset("tbl_PPSservOps")
Set source3 = db.OpenRecordset("qry_CommonServTempl")
Set dest3 = db.OpenRecordset("tbl_CommonServTempl")
Set source4 = db.OpenRecordset("qry_CommonServTempl_CP")
Do Until source3.EOF()
dest3.AddNew
dest3![common servcode] = source3![commonServCode]
dest3!Operation = source3![OperationNo]
dest3!Description = source3!Cause
dest3![Vendor] = source3![Vendor]
dest3![Type Class] = source3![TypeClass]
dest3![Data ID] = source3![DataID]
dest3![t1 Code] = source3![T1code]
dest3![T2 Code] = source3![T2code]
dest3![Condition] = source3![VehicleDescription]
dest3![Cause] = source3![Cause]
dest3![Remedy] = source3![Remedy]
'dest3![ItemNo] = source3![]
dest3![item type] = source3![ItemType]
dest3![Part No] = source3![PartNumber]
dest3![Operation No] = source3![OperationNo]
dest3![Subl Type] = source3![SubletType]
dest3![DDUC Type] = source3![DeductionType]
dest3![Quant] = source3![PartQty]
dest3![UOM] = source3![UOM]
dest3![Part_Description] = source3![PartDescription]
dest3![Service] = source3![ServiceNumber]
If source3![CategoryID] = "2" Or source3![CategoryID] = "3" Then
dest3![Part No] = "SUBLET"
dest3![SUBL INV NO] = "RCL itm"
dest3![Operation No] = Null
Else
If source3![ItemType] = "FR" Then
dest3![Part No] = Null
dest3![Part_Description] = source3![Cause]
Else
dest3![Operation No] = Null
End If
End If
dest3.Update
source3.MoveNext
Loop
Do Until source4.EOF()
dest3.AddNew
dest3![common servcode] = source4![commonServCode]
dest3!Operation = source4![OperationNo]
dest3!Description = source4!Cause
dest3![Vendor] = source4![Vendor]
dest3![Type Class] = source4![TypeClass]
dest3![Data ID] = source4![DataID]
dest3![t1 Code] = source4![T1code]
dest3![T2 Code] = source4![T2code]
dest3![Condition] = source4![VehicleDescription]
dest3![Cause] = source4![Cause]
dest3![Remedy] = source4![Remedy]
'dest3![ItemNo] = source4![]
dest3![item type] = source4![ItemType]
dest3![Part No] = "SUBLET"
dest3![Subl Type] = source4![SubletType]
dest3![DDUC Type] = source4![DeductionType]
dest3![Quant] = "1"
dest3![UOM] = "EA"
dest3![SUBL INV NO] = "RCL itm"
dest3![Part_Description] = "Customer Payment"
dest3![Service] = source4![Service]
dest3.Update
source4.MoveNext
Loop
dest3.Sort = "[common Servcode]" & "[Service]"