Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
UPDATE I have turned Option Strict ON as suggested in the comments and fixed the errors, however the VAT is still not calculating correctly, here is a GIST link to the full function
I have a problem with the VAT rate not calculating correctly,
the MOT line should always be set at 0% and the BOMOT line should set based on the customers VAT code (this customer has the standard 20% VAT code and as you can see it is set correctly
when i change the customer to my 0 rated VAT customer the code again calculates correctly,
now when i change the customer back from this to a Standard VAT customer it recalculates incorrect and changes the MOT line to 20% when it should be zero
Here is the code that calculates the VAT
Dim FPVATCode As String = 1
Dim FPVATRate As Decimal = 0
If c.LoadCode("V", FPVATCode, "") Then
FPVATRate = Val(c.Rec!a2)
End If
If customerVATRate <> -1 Then
If customerVATRate < FPVATRate Then
line.VCode = customerVATCode
Else
line.VCode = FPVATCode
End If
Else
line.VCode = FPVATCode
End If
THE FULL FUNCTION Link to full function
Public Sub RecalculateDocumentPrices(ByVal NewCust As String) 'V749910 (163.18)
Dim newCustomer As New customer
newCustomer.LoadNewCustomer(NewCust)
' Get the customer VAT rate
Dim customerVATCode As String = newCustomer.GetVCode
Dim customerVATRate As Decimal = -1
Dim bAutoPartLinked As Boolean = Settings.AutoPartLinked
Dim c As New Codes
If c.LoadCode("V", customerVATCode, "") Then
customerVATRate = Val(c.Rec!a2)
End If
'L762946 (163.34) - only attempt recalculation if there are some lines on the document
If Not lines Is Nothing Then
For Each line As Line In lines
line.disc = 0
Select Case line.LineType
Case line.lineTypes.P, line.lineTypes.LT, line.lineTypes.SS, line.lineTypes.TA
'for a regular (ie. Non Branch Stock) product, get the price
If line.DescKey2 Is Nothing OrElse line.DescKey2.ToLower <> "branch" Then
''get the product price
Dim p As New Product
If p.LoadProduct(line.Part, , newCustomer.Rec!Cdisc, NewCust) Then 'V772656 (163.65) - pass the selling level of the new customer
'V749910 (163.19) - use the lower of the customer & product VAT rates
Dim productVATCode As String = p.Rec!Vcode
Dim productVATRate As Decimal = 0
If c.LoadCode("V", productVATCode, "") Then
productVATRate = Val(c.Rec!a2)
End If
If customerVATRate <> -1 Then
If customerVATRate < productVATRate Then
line.VCode = customerVATCode
Else
line.VCode = p.Rec!vcode
End If
Else
line.VCode = p.Rec!vcode
End If
'Remove VatIncCheck - V838410 (1.0.164.5)
'set the VatInclusive price if appropriate
'If newCustomer.IsVATInclusiveCustomer Then
' 'For a non linked system, add the VAT to the price
' Dim sellPrice As Decimal = p.sMSell
' If Not Settings.AutoPartLinked Then
' sellPrice *= Math.Round((1 + (line.vatRate / 100)), 2, MidpointRounding.AwayFromZero)
' End If
' line.IsVATInclusivePrice = True
' line.VatInclusivePrice = sellPrice
'Else
'V772656 (163.65) - was setting the unit price THEN the VAT Inc price THEN setting IsVatInclusivePrice to false. Therefore
'the unit price was being overwritten.
line.IsVATInclusivePrice = False
line.VatInclusivePrice = 0
If bAutoPartLinked Then 'L811755 (1.0.163.105)
line.unit = p.sMSell
End If
'End If
'Apply markon
CalcMarkon(line)
End If
Else
'for a Branch Stock product, perform a supplier enquiry to obtain the price
Dim awdTmp As New AutoworkDocument
Dim l As New Line
l.Part = line.Part
awdTmp.LookupLine(l)
'V749910 (163.19) - use the lower of the customer & product VAT rates
Dim productVATCode As Integer = 1
Dim productVATRate As Decimal = 0
If c.LoadCode("V", productVATCode, "") Then
productVATRate = Val(c.Rec!a2)
End If
If customerVATRate <> -1 Then
If customerVATRate < productVATRate Then
line.VCode = customerVATCode
Else
line.VCode = productVATCode
End If
Else
line.VCode = productVATCode
End If
'set the VatInclusive price if appropriate
If newCustomer.IsVATInclusiveCustomer Then
'Branch stock not available to Linked mode so just apply the vat
line.IsVATInclusivePrice = True
line.VatInclusivePrice = Math.Round(l.unit * (1 + (line.vatRate / 100)), 2, MidpointRounding.AwayFromZero)
Else
'V772656 (163.65) - was setting the unit price THEN the VAT Inc price THEN setting IsVatInclusivePrice to false. Therefore
'the unit price was being overwritten.
line.IsVATInclusivePrice = False
line.VatInclusivePrice = 0
line.unit = l.unit
End If
'Apply markon
CalcMarkon(line)
End If
Case line.lineTypes.FPP 'L829840 (1.0.163.123)
Case line.lineTypes.L 'V831093 (1.0.163.123)
'set the VatInclusive price if appropriate
If newCustomer.IsVATInclusiveCustomer Then 'V831093 (1.0.163.125)
'Branch stock not available to Linked mode so just apply the vat
line.IsVATInclusivePrice = True
line.VatInclusivePrice = Math.Round(line.unit * (1 + (line.vatRate / 100)), 2, MidpointRounding.AwayFromZero)
Else
'V772656 (163.65) - was setting the unit price THEN the VAT Inc price THEN setting IsVatInclusivePrice to false. Therefore
'the unit price was being overwritten.
line.IsVATInclusivePrice = False
line.VatInclusivePrice = 0
line.unit = line.unit
End If
Case line.lineTypes.FP
'get the selling price of the fixed price job
Dim cj As New CustomJobs
Dim ds As DataSet
Dim dv As DataView
ds = cj.LoadCustomJob(line.Part)
dv = ds.Tables("CustomJob").DefaultView
Dim dvHead As DataView = ds.Tables("JobHeader").DefaultView
If dvHead.Table.Rows.Count > 0 Then ''00518984 (1.0.163.105)
line.cost = CType(dvHead.Table.Rows(0)("FpCost"), Decimal)
'V749910 (163.19) - use the lower of the customer & product VAT rates
'V749910 (163.18) - If a VATInclusive line, set the VATInclusive price
If newCustomer.IsVATInclusiveCustomer Then
line.IsVATInclusivePrice = True
line.VatInclusivePrice = Math.Round(dvHead.Table.Rows(0)("FpSell") * (1 + (line.vatRate / 100)), 2, MidpointRounding.AwayFromZero)
Else
'V772656 (163.65) - was setting the unit price THEN the VAT Inc price THEN setting IsVatInclusivePrice to false. Therefore
'the unit price was being overwritten.
line.IsVATInclusivePrice = False
line.VatInclusivePrice = 0
line.unit = CType(dvHead.Table.Rows(0)("FpSell"), Decimal)
End If
End If ''00518984 END
Dim FPVATCode As String = CType(1, String)
Dim FPVATRate As Decimal = 0
If c.LoadCode("V", FPVATCode, "") Then
FPVATRate = CType(Val(c.Rec!a2), Decimal)
End If
If customerVATRate <> -1 Then
If customerVATRate < FPVATRate Then
line.VCode = CType(customerVATCode, Short)
Else
line.VCode = CType(FPVATCode, Short)
End If
Else
line.VCode = CType(FPVATCode, Short)
End If
Case line.lineTypes.CON
'just set the ISVatInclusive flag on this line. The consumables amount is calculated once all lines have been processed by the SaveSess().
line.VCode = customerVATCode
line.IsVATInclusivePrice = newCustomer.IsVATInclusiveCustomer
End Select
Next
End If
End Sub
Now resolved, VAT was being calculated from products in the wrong table,
inserted this conditional in the method and it fixed it,
'00518984 Calculates VAT for items in the labour table
Dim lB As New Product
Dim dv1 As DataView = lB.LabourSearch(line.Part)
If dv1.Table.Rows.Count > 0 Then
Dim dr1 As DataRow = dv1.ToTable.Rows(0)
Dim PVCode As Integer = dr1("VCode")
Beep()
line.VCode = PVCode
Else
Dim FPVATCode As String = CType(1, String)
Dim FPVATRate As Decimal = 0
If c.LoadCode("V", FPVATCode, "") Then
FPVATRate = CType(Val(c.Rec!a2), Decimal)
End If
line.VCode = customerVATCode
End If
'00518984 END
Related
I am using Access 2010. I have a datasheet form called Projects with two fields, [Project Name] and [Priority]. I would like to be able to update the priority number for one of the records and have all other priority numbers update automatically. For example, Project Red is priority 1. Project Orange is Priority 2 and Project Blue is Priority 3. If I update Blue to number 1, I would like Red to update to 2 and Orange to update to 3. Is this possible?
Projects Form
That is possible.
Use the AfterUpdate event of the textbox with Priority:
Private Sub Priority_AfterUpdate()
Dim rst As DAO.Recordset
Dim lngId As Long
Dim lngPriorityNew As Long
Dim lngPriorityFix As Long
' Save record.
Me.Dirty = False
' Prepare form.
DoCmd.Hourglass True
Me.Repaint
Me.Painting = False
' Current Id and priority.
lngId = Me!Id.Value
lngPriorityFix = Nz(Me!Priority.Value, 0)
If lngPriorityFix <= 0 Then
lngPriorityFix = 1
Me!Priority.Value = lngPriorityFix
Me.Dirty = False
End If
' Rebuild priority list.
Set rst = Me.RecordsetClone
rst.MoveFirst
While rst.EOF = False
If rst!Id.Value <> lngId Then
lngPriorityNew = lngPriorityNew + 1
If lngPriorityNew = lngPriorityFix Then
' Move this record to next lower priority.
lngPriorityNew = lngPriorityNew + 1
End If
If Nz(rst!Priority.Value, 0) = lngPriorityNew Then
' Priority hasn't changed for this record.
Else
' Assign new priority.
rst.Edit
rst!Priority.Value = lngPriorityNew
rst.Update
End If
End If
rst.MoveNext
Wend
' Reorder form and relocate record.
Me.Requery
Set rst = Me.RecordsetClone
rst.FindFirst "Id = " & lngId & ""
Me.Bookmark = rst.Bookmark
' Present form.
Me.Painting = True
DoCmd.Hourglass False
Set rst = Nothing
End Sub
I am newish to MS Access.
I require the equivalent formula from excel to mc access which will workout -1 day from my data-set less weekends/public holidays.
So this is what i use in excel atm: =WORKDAY(start date,days,[holidays])
Any help would be greatly appreciated.
There is no native function, but you can use this set of functions:
Option Explicit
' Common constants.
' Date.
Public Const DaysPerWeek As Long = 7
Public Const MaxDateValue As Date = #12/31/9999#
Public Const MinDateValue As Date = #1/1/100#
' Workdays per week.
Public Const WorkDaysPerWeek As Long = 5
' Average count of holidays per week maximum.
Public Const HolidaysPerWeek As Long = 1
' Adds Number of full workdays to Date1 and returns the found date.
' Number can be positive, zero, or negative.
' Optionally, if WorkOnHolidays is True, holidays are counted as workdays.
'
' For excessive parameters that would return dates outside the range
' of Date, either 100-01-01 or 9999-12-31 is returned.
'
' Will add 500 workdays in about 0.01 second.
'
' Requires table Holiday with list of holidays.
'
' 2015-12-19. Gustav Brock. Cactus Data ApS, CPH.
'
Public Function DateAddWorkdays( _
ByVal Number As Long, _
ByVal Date1 As Date, _
Optional ByVal WorkOnHolidays As Boolean) _
As Date
Const Interval As String = "d"
Dim Holidays() As Date
Dim Days As Long
Dim DayDiff As Long
Dim MaxDayDiff As Long
Dim Sign As Long
Dim Date2 As Date
Dim NextDate As Date
Dim DateLimit As Date
Dim HolidayId As Long
Sign = Sgn(Number)
NextDate = Date1
If Sign <> 0 Then
If WorkOnHolidays = True Then
' Holidays are workdays.
Else
' Retrieve array with holidays between Date1 and Date1 + MaxDayDiff.
' Calculate the maximum calendar days per workweek.
MaxDayDiff = Number * DaysPerWeek / (WorkDaysPerWeek - HolidaysPerWeek)
' Add one week to cover cases where a week contains multiple holidays.
MaxDayDiff = MaxDayDiff + Sgn(MaxDayDiff) * DaysPerWeek
If Sign > 0 Then
If DateDiff(Interval, Date1, MaxDateValue) < MaxDayDiff Then
MaxDayDiff = DateDiff(Interval, Date1, MaxDateValue)
End If
Else
If DateDiff(Interval, Date1, MinDateValue) > MaxDayDiff Then
MaxDayDiff = DateDiff(Interval, Date1, MinDateValue)
End If
End If
Date2 = DateAdd(Interval, MaxDayDiff, Date1)
' Retrive array with holidays.
Holidays = GetHolidays(Date1, Date2)
End If
Do Until Days = Number
If Sign = 1 Then
DateLimit = MaxDateValue
Else
DateLimit = MinDateValue
End If
If DateDiff(Interval, DateAdd(Interval, DayDiff, Date1), DateLimit) = 0 Then
' Limit of date range has been reached.
Exit Do
End If
DayDiff = DayDiff + Sign
NextDate = DateAdd(Interval, DayDiff, Date1)
Select Case Weekday(NextDate)
Case vbSaturday, vbSunday
' Skip weekend.
Case Else
' Check for holidays to skip.
' Ignore error when using LBound and UBound on an unassigned array.
On Error Resume Next
For HolidayId = LBound(Holidays) To UBound(Holidays)
If Err.Number > 0 Then
' No holidays between Date1 and Date2.
ElseIf DateDiff(Interval, NextDate, Holidays(HolidayId)) = 0 Then
' This NextDate hits a holiday.
' Subtract one day before adding one after the loop.
Days = Days - Sign
Exit For
End If
Next
On Error GoTo 0
Days = Days + Sign
End Select
Loop
End If
DateAddWorkdays = NextDate
End Function
' Returns the holidays between Date1 and Date2.
' The holidays are returned as a recordset with the
' dates ordered ascending, optionally descending.
'
' Requires table Holiday with list of holidays.
'
' 2015-12-18. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function DatesHoliday( _
ByVal Date1 As Date, _
ByVal Date2 As Date, _
Optional ByVal ReverseOrder As Boolean) _
As DAO.Recordset
' The table that holds the holidays.
Const Table As String = "Holiday"
' The field of the table that holds the dates of the holidays.
Const Field As String = "Date"
Dim rs As DAO.Recordset
Dim SQL As String
Dim SqlDate1 As String
Dim SqlDate2 As String
Dim Order As String
SqlDate1 = Format(Date1, "\#yyyy\/mm\/dd\#")
SqlDate2 = Format(Date2, "\#yyyy\/mm\/dd\#")
ReverseOrder = ReverseOrder Xor (DateDiff("d", Date1, Date2) < 0)
Order = IIf(ReverseOrder, "Desc", "Asc")
SQL = "Select " & Field & " From " & Table & " " & _
"Where " & Field & " Between " & SqlDate1 & " And " & SqlDate2 & " " & _
"Order By 1 " & Order
Set rs = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)
Set DatesHoliday = rs
End Function
' Returns the holidays between Date1 and Date2.
' The holidays are returned as an array with the
' dates ordered ascending, optionally descending.
'
' The array is declared static to speed up
' repeated calls with identical date parameters.
'
' Requires table Holiday with list of holidays.
'
' 2015-12-18. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function GetHolidays( _
ByVal Date1 As Date, _
ByVal Date2 As Date, _
Optional ByVal OrderDesc As Boolean) _
As Date()
' Constants for the arrays.
Const DimRecordCount As Long = 2
Const DimFieldOne As Long = 0
Static Date1Last As Date
Static Date2Last As Date
Static OrderLast As Boolean
Static DayRows As Variant
Static Days As Long
Dim rs As DAO.Recordset
' Cannot be declared Static.
Dim Holidays() As Date
If DateDiff("d", Date1, Date1Last) <> 0 Or _
DateDiff("d", Date2, Date2Last) <> 0 Or _
OrderDesc <> OrderLast Then
' Retrieve new range of holidays.
Set rs = DatesHoliday(Date1, Date2, OrderDesc)
' Save the current set of date parameters.
Date1Last = Date1
Date2Last = Date2
OrderLast = OrderDesc
Days = rs.RecordCount
If Days > 0 Then
' As repeated calls may happen, do a movefirst.
rs.MoveFirst
DayRows = rs.GetRows(Days)
' rs is now positioned at the last record.
End If
rs.Close
End If
If Days = 0 Then
' Leave Holidays() as an unassigned array.
Erase Holidays
Else
' Fill array to return.
ReDim Holidays(Days - 1)
For Days = LBound(DayRows, DimRecordCount) To UBound(DayRows, DimRecordCount)
Holidays(Days) = DayRows(DimFieldOne, Days)
Next
End If
Set rs = Nothing
GetHolidays = Holidays()
End Function
I have this code to access:
Option Compare Database
Public Sub batchAdd(records As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("tblMeters")
i = 1
Do While i <= records
rs.AddNew
rs!value1 = Me.value1
rs!Ticket = Me.Ticket
rs!value2 = Me.value2
rs!value3 = Me.value3
rs!value4 = Me.value4
rs!value5 = Me.value5
rs!value6 = Me.value6
rs!value7 = Me.value7
rs.Update
i = i + 1
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Private Sub cmdAddRecords_Click()
batchAdd Me.txtRecords
Me.tblMeters_sub.Requery
End Sub
My question was how to increase the ticket value of +1 for each record inserted.
Example: If I insert the ticket with a value of 1 to 10 times, the first time will be 1 and the second 2, then 3 .... how do I change this code for the ticket value?
Adjust this line to:
rs!Ticket = i
I have a recursive function that creates a list of items based on their hierarchy(integer is used to determine which level 1 to 10 max). There can be x number of items in any given level. I want to store all the items that belong the same level at the corresponding index of the jagged array. The items aren't retrieved based on their level so the level can be jumping around all of over the place as the function recurses.
Function RecurseParts(lngPartID1, lngLevel) As Object
'this function will recursivley print the parts lists for the part ID passed in
If IsNumeric(lngPartID1 & "") Then
Dim objRSTemp As Object = Server.CreateObject("ADODB.Recordset")
objRSTemp.CursorLocation = adUseClient
objRSTemp.Open(PART_LIST_SQL & lngPartID1, objConn, adOpenForwardOnly, adLockReadOnly)
'objRSTemp.ActiveConnection = Nothing
If objRSTemp.eof And objRSTemp.bof Then
'PROBLEM, WE HAVE NO RECORDS
Response.Write("There Were No Parts For This Assembly (Part ID #:" & lngPartID1 & ")")
Else
'make output
Dim strTemp As String = String.Empty
If lngLevel <> 1 Then strTemp = " style=""display: none;"">"
Response.Write("<table id='tblparts" & lngCurrentLineNum & "' border=""0"" cellspacing=""0"" width=""100%"" cellpadding=""1"" " & strTemp)
Do Until objRSTemp.EOF
'increase the current line num
lngCurrentLineNum = lngCurrentLineNum + 1
'get current Part ID
lngCurrentPartID = objRSTemp("PartID").value
'reset flag
blnIsAssm = False
'loop thru array of assemblies to see if this is a parent
For ctr = 0 To UBound(arrAssmList, 2)
If arrAssmList(0, ctr) = lngCurrentPartID Then
'the current part is an assembly
blnIsAssm = True
Exit For
ElseIf arrAssmList(0, ctr) > lngCurrentPartID Then
Exit For
End If
Next
If blnIsAssm Then
'recurse these parts
If RecurseParts(objRSTemp("PartID").value, lngLevel + 1) = True Then
'awesome
End If
End If
objRSTemp.MoveNext()
Loop
Response.Write("</table>")
End If
If objRSTemp.State Then objRSTemp.Close()
objRSTemp = Nothing
'RETURN FUNCTION
RecurseParts = True
Else
'no PART ID passed in
Response.Write("No Part ID Passed In")
RecurseParts = False
End If
End Function
It sounds like a Dictionary would work here.
Dim myDict As New Dictionary(Of Integer, List(Of String))
In your recursive function. The parts in the {} are the parts you have to supply.
'this builds the keys as you go
If Not myDict.ContainsKey({{key} -> your Integer}) Then
'add key and use the From statement to add a value if know at this time
myDict.Add({key}, New List(Of String) From {value})
Else
myDict({key}).Add({string to insert at this level})
End If
List of keys in reverse order:
Dim keys = myDict.Keys.OrderByDescending(Function(k) k)
I was able to create a List to store all the partIDs and their levels.
Dim arrSubID As New List(Of List(Of Integer))()
Function RecurseParts(paramenters)
For ctr = 0 To UBound(arrAssmList, 2)
If arrAssmList(0, ctr) = lngCurrentPartID Then
'checks whether we need a new index in the list
If lngLevel + 1 > arrSubID.Count Then
arrSubID.Add(New List(Of Integer))
End If
'adds the partID where it belongs!
arrSubID(lngLevel).Add(lngCurrentPartID)
blnIsAssm = True
Exit For
ElseIf arrAssmList(0, ctr) > lngCurrentPartID Then
Exit For
End If
Next
End Function
I'm programming in Classic ASP. I'm trying to do the paging. My backend is SQL CE 3.5. Unfortunetly, it doesn't support paging in SQL Query (Like row_number() in sql server).
So I go with ASP Paging. But when i ask to the recordset, give me the first 10 records by setting the rs.PageSize and rs.AbsolutePage and all, it gives me all records. So I planned to copy only first 10 rows from the resultant recordset to another new recordset. So I coded like below:
Set rsTemp = CopyRecordsetStructure(objRs)
rsTemp.Open
iRecordsShown = 0
Set objFields = objRs.Fields
intFieldsCount = objFields.Count-1
Do While iRecordsShown < intPageSize And Not objRs.EOF
rsTemp.AddNew
For Idx = 0 To intFieldsCount
rsTemp.Fields(Idx).Value = objRs.Fields(Idx).Value
Next
rsTemp.Update
iRecordsShown = iRecordsShown + 1
objRs.MoveNext
Loop
Public Function CopyRecordsetStructure(ByVal rs)
Dim rsTemp
Set rsTemp = CreateObject("ADODB.Recordset")
Set objFields = rsTemp.Fields
intFieldCount = objFields.Count - 1
For Idx = 0 To intFieldCount
rsTemp.Fields.Append objFields(Idx).Name, _
objFields(Idx).Type, _
objFields(Idx).DefinedSize
Next
Set CopyRecordsetStructure = rsTemp
End Function
The issue is i could not open the" rsTemp". It throws me error
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
If I use some dummy query and connection it doesn't work.
Please help to copy the records from one recordset to another new record set.
Thanks in advance
Ganesh.
Not sure, but this looks wrong
Set objFields = rsTemp.Fields
Shouldn't it be
Set objFields = rs.Fields
With the comments and fixed in the above comments, the function should be updated Set objFields = rs.Fields to:
Usage:
Dim rsTemp
Set rsTemp = CopyRecordset(rsPadicon)
Update Code
Public Function CopyRecordset(rs)
Dim rsTemp, objFields, intFieldsCount, intPageSize
Set rsTemp = CopyRecordsetStructure(rs)
rsTemp.Open
Set objFields = rs.Fields
intFieldsCount = objFields.Count-1
response.write("<li> rs.RecordCount :" & rs.RecordCount & "</li>")
' response.write("<li> intFieldsCount :" & intFieldsCount & "</li>")
rs.MoveFirst
Do While Not rs.EOF
rsTemp.AddNew
Dim i
For i = 0 to intFieldsCount 'use i as a counter
' response.write("<li> Name :" & rs.Fields(i).Name & "</li>")
' response.write("<li> Value :" & rs.Fields(i).Value & "</li>")
if Not IsNull(rs.Fields(i).Value) then
rsTemp.Fields(i).Value = rs.Fields(i).Value
End if
Next
rsTemp.Update
rs.MoveNext
Loop
Set CopyRecordset = rsTemp
End Function
Public Function CopyRecordsetStructure(ByVal rs)
Dim rsTemp, objFields, intFieldCount, Idx
Set rsTemp = CreateObject("ADODB.Recordset")
Set objFields = rs.Fields
intFieldCount = objFields.Count - 1
For Idx = 0 To intFieldCount
rsTemp.Fields.Append objFields(Idx).Name, _
objFields(Idx).Type, _
objFields(Idx).DefinedSize
Next
Set CopyRecordsetStructure = rsTemp
End Function