Access 2010 VBA or query a table and calculate the results - ms-access

I have a table that contains prices from several agents and from several airlines, they were divided into groups by weight charges.
Depending on the airport of departure (POL/C) and arrival (POD/C), I check all the prices and I have to use the best one. But to show the price alternatives.
Each airline has its own method of calculation, therefore I have to check.
Table contains the following information:
ID = AutoNumber, Long Integer
A/CODE = Number, Long Integer
AGENT = Text,
POL/C = Text,
POL = Text,
POD/C = Text,
POD = Text,
IATA = Text,
Airline = Text,
UPDATE = Date/Time, Short Date
EXPIRY DATE = Date/Time, Short Date
CURRENCY = Text,
M/M = Number, Double (Minimum weight accepted)
-45 = Number, Double (price for the weight between 1 and 45)
+45 = Number, Double (price for the weight starting from 45 to 100)
+100 = Number, Double (price for the weight starting from 100 to 300)
+300 = Number, Double (price for the weight starting from 300 to 500)
+500 = Number, Double (price for the weight starting from 500 to 1000)
+1000 = Number, Double (price for the weight starting from 1000)
FSC = Number, Double
SSC = Number, Double
ScGw = Yes/No, Yes/No
FREQUENCY = Text,
TT = Number, Long Integer
T/S = Yes/No, Yes/No
From the beginning it will have two weights as follows:
actual total weight (GW - gross weight)
calculated weight by volume (VW)
if GW > VW then..
calculation is based on the higher value (GW)
else
calculation is based on the higher value (VW)
example:
VW = 405 kgs and GW = 222 kgs then use higher value
FSC and SSC is added to the price if any.
Where is calculated on weight (VW) and If ScGw = Yes THEN the weight is different account and is calculated using (GW)
example:
Air freight = euro 0.25 / kgs (x 405 kgs VW)
Fuel + security = euro 1.1 / kgs (x 222 kgs GW)
If ScGw = No THEN calculate the normal VW
example:
Air freight = euro 0.25 / kgs (x 405 kgs VW)
Fuel + security = euro 1.1 / kgs (x 405 kgs VW)
If the calculation is made according to GW,
then add the FSC and SSC automatically and without having to count,
if ScGw = Yes / No
Values of GW and VW we have already calculated in another form and only need to be use.
airport of departure (POL/C) and arrival (POD/C) is already selected in another form.
If you can help me, as a few days simply fail to find any solution. I am writing full pages without any good result.
Thanks to all who respond.
I'm stuck at the moment and with the error:
Run-time error ‘3061’:
Too few parameters. Expected 2
I do not know what the problem is...
Public Sub CalculPret()
Dim da As Database
Dim rec As Recordset
Dim PolCboV As String
Dim PodCboV As String
Dim strSQL As String
Dim GrossWeight As Double
Dim VolumeWeight As Double
Dim CalcWeight As Double
Dim CalcWeightScGw As Double
Dim CalcPrice As Double
Dim TotalPrice As Double
PolCboV = [Forms]![DimensionsQry]![PolCbo]
PodCboV = [Forms]![DimensionsQry]![PodCbo]
strSQL = "SELECT Prices_List.ID, Prices_List.[A/CODE], Prices_List.AGENT, Prices_List.[POL/C], Prices_List.POL, Prices_List.[POD/C], Prices_List.POD, Prices_List.IATA, Prices_List.AIRLINE, Prices_List.UPDATE, Prices_List.[EXPIRY DATE], Prices_List.CURRENCY, Prices_List.[M/M], Prices_List.[-45], Prices_List.[+45], Prices_List.[+100], Prices_List.[+300], Prices_List.[+500], Prices_List.[+1000], Prices_List.FSC, Prices_List.SSC, Prices_List.ScGw, Prices_List.FREQUENCY, Prices_List.TT, Prices_List.[T/S]"
strSQL = strSQL & " FROM Prices_List"
strSQL = strSQL & " WHERE (((Prices_List.[POL/C])=PolCboV) AND ((Prices_List.[POD/C])=PodCboV)); "
Set da = CurrentDb
Set rec = da.OpenRecordset(strSQL)
If rec.RecordCount = 0 Then
rec.Close
Exit Sub
Else
GrossWeight = [Forms]![DimensionsQry]![Text34]
VolumeWeight = [Forms]![DimensionsQry]![Text36]
If GrossWeight > VolumeWeight Then
CalcWeight = GrossWeight
Else
If ScGw = "Yes" Then
CalcWeight = GrossWeight
Else
CalcWeight = VolumeWeight
End If
End If
rec.MoveFirst
Do Until rec.EOF
Select Case CalcWeight
Case 1 To 44
CalcPrice = rec![-45]
Case 45 To 99
CalcPrice = rec![+45]
Case 100 To 299
CalcPrice = rec![+100]
Case 300 To 499
CalcPrice = rec![+300]
Case 500 To 999
CalcPrice = rec![+500]
Case Is >= 1000
CalcPrice = rec![+1000]
End Select
If CalcWeight = GrossWeight Then
CalcPrice = CalcPrice + rec!FSC + rec!SSC
TotalPrice = CalcPrice * CalcWeight
Else
TotalPrice = (CalcPrice * CalcWeight) + ((rec!FSC + rec!SSC) * GrossWeight)
End If
MsgBox TotalPrice
rec.MoveNext
Loop
End If
rec.Close
End Sub

I have tried to rearrange your rules into execution sequence.
I have added the following variables:
CalcWeight: The weight to be used in the calculation
CalcPrice: The price to be used in the calculation
TotalPrice: Price based on weight, standard price, fuel and security
Does the following look about right?
If GrossWeight > VolumeWeight Then
CalcWeight = GrossWeight
Else
If ScGw = "Yes" Then
CalcWeight = GrossWeight
Else
CalcWeight = VolumeWeight
End If
End If
Select Case CalcWeight
Case 1 To 44
CalcPrice = Price(-45)
Case 45 to 99
CalcPrice = Price(+45)
Case 100 To 299
CalcPrice = Price(+100)
Case 300 To 499
CalcPrice = Price(+300)
Case 500 To 999
CalcPrice = Price(500)
Case Is >= 1000
CalcPrice = Price(1000)
End Select
' I am unclear about adding FSC and SSC to CalcPrice.
' It appears to be based on which weight is used but
' it may be more complicated.
If CalcWeight = GrossWeight Then
CalcPrice = CalcPrice + FSC + SSC
End If
TotalPrice = CalcPrice * CalcWeight
New section in response to extra question
I have two problems:
You do not say which statement gives the 3061 error although I suspect I know.
I have not used Access for some years.
Everything that follows is general advice that may help you isolate the cause of the error.
Issue 1
strSQL = "SELECT Prices_List.ID, Prices_List.[A/CODE], Prices_List.AGENT, Prices_List.[POL/C], Prices_List.POL, Prices_List.[POD/C], Prices_List.POD, Prices_List.IATA, Prices_List.AIRLINE, Prices_List.UPDATE, Prices_List.[EXPIRY DATE], Prices_List.CURRENCY, Prices_List.[M/M], Prices_List.[-45], Prices_List.[+45], Prices_List.[+100], Prices_List.[+300], Prices_List.[+500], Prices_List.[+1000], Prices_List.FSC, Prices_List.SSC, Prices_List.ScGw, Prices_List.FREQUENCY, Prices_List.TT, Prices_List.[T/S]"
I do not like long statements that run off the page. I would have typed this as:
strSQL = "SELECT Prices_List.ID, Prices_List.[A/CODE], Prices_List.AGENT, " & _
"Prices_List.[POL/C], Prices_List.POL, Prices_List.[POD/C], " & _
"Prices_List.POD, Prices_List.IATA, Prices_List.AIRLINE, " & _
"Prices_List.UPDATE, Prices_List.[EXPIRY DATE], Prices_List.CURRENCY, " & _
"Prices_List.[M/M], Prices_List.[-45], Prices_List.[+45], " & _
"Prices_List.[+100], Prices_List.[+300], Prices_List.[+500], " & _
"Prices_List.[+1000], Prices_List.FSC, Prices_List.SSC, " & _
"Prices_List.ScGw, Prices_List.FREQUENCY, Prices_List.TT, " & _
"Prices_List.[T/S]"
Issue 2
Do you need all these fields? When you have picked the best price you will need AGENT or A/CODE. If you do not need ID, IATA, AIRLINE, why select them?
Issue 3
You have a field CURRENCY which you do not use. Is this correct?
Issue 4
Set da = CurrentDb
I assume CurrentDb is a global variable because it is not declared or set within this subroutine.
Issue 5
Set rec = da.OpenRecordset(strSQL)
I have googled "Access Error 3061" and have received lots of questions and answers about this error. Perhaps one will help you.
If I understand correctly, Prices_List is not a table but a query with parameters and you have not included the parameters.
Issue 5
MsgBox TotalPrice
While you are trying to get your program working, Debug.Print is more useful than MsgBox.
Click on one of the early statements in this routine to place the cursor in it. Click F9. The statement will go brown to indicate it is a breakpoint.
Run your program in the normal way. When it gets to the brown statement, it will stop and display the module. The brown statement will be both brown and yellow. Brown because it is a breakpoint; yellow because it is the statement about to be executed. Click F8; one statement will be executed and the next statement will become the yellow one.
You can step through your program statement by statement checking what is happening. If you hover over a variable, its current value will be displayed. If a statement gives an error, you can change it and try again.
You can have as many breakpoints as you like. Clicking F5 causes the program to run until the next breakpoint. With F5 and F8 you can control which bits of your program you examine.
Debug.Assert rec!AGENT <> "Acme Inc" can be very useful if one part of your program is failing. This debug assert will stop the program if the agent is "Acme Inc". The syntax is Debug.Assert boolean expression. With the correct boolean expression you can stop your program where ever you want.
At the bottom of the editor screen you should see the Immediate window. If you do not, click Ctrl+G.
Debug.Print rec!AGENT & " " & TotalPrice
will output Acme Inc 543.21 to the Immediate Window and carry on. With MsgBox the program stops and you have to write down the value. The Immediate Window has a limit of two or three hundred lines which you can scroll up and down or copy to NotePad.
Summary
I hope the above helps. Best of luck.

the line
strSQL = strSQL & " WHERE (((Prices_List.[POL/C])=PolCboV) AND ((Prices_List.[POD/C])=PodCboV));"
should read
strSQL = strSQL & " WHERE (((Prices_List.[POL/C])='" & PolCboV & "') AND ((Prices_List.[POD/C])='" & PodCboV & "'));"
because PolCbov & PodCbov are variables in your code, you want their values in the SQL not their names

Related

ACCESS sql code to multiply record with calculated value from previous cell

I am using Access Database to get a value. I am fairly new to access as I usually use SQLServer and I am having trouble in getting what I want.
I have the following table, with column TARGET and incremental Target as the target column that I need to get:
Category|Period|Value| TARGET |
A | 4 | 1 | 1/1 =1 |
A | 3 | 3 | 1/(3*1)=0.33 | (1/value at period 3 * previous target)
A | 2 | 6 |1/(0.33*6)=0.505|
A | 1 | 9 |1/(0.505*9)=0.22|
The data is partitioned by Category and ordered in descending order by Period.
For the first row the Target should be: (1/value at current period)
For the next rows the Target should be: (1/value at current period * value of previous target)
As you can see this is somehow complex as I need to evaluate a cell value and then for the next row I need to use the value in the cell above.
Plus I need to get the incremental value for this column as well.
Any help will be very much appreciated as I am new to Access and need to get this done soon!
Here is a function placed in general module that can be called from query. Value is a reserved word so I used Data for that field name.
Option Compare Database
Option Explicit
Global dblTar As Double
Global strCat As String
____________
Function CalcTarget(strC As String, dblT As Double) As Double
If strCat <> strC Then
strCat = strC
dblTar = dblT
End If
dblTar = 1 / (dblT * dblTar)
CalcTarget = dblTar
End Function
Calling function in query:
SELECT Category, Period, Data, CalcTarget([Category],[Data]) AS Target FROM Table1;
Normally I advise not to save calculated data to table when a query can work, but if you prefer to save, then options are:
An UPDATE action: UPDATE Table1 SET Target = CalcTarget([Category],[Data]);
Or VBA:
Sub CalcTarget()
Dim rs As DAO.Recordset
Dim strCat As String
Dim dblTar As Double
Set rs = CurrentDb.OpenRecordset("SELECT * FROM table1 ORDER BY Category, Period DESC")
strCat = rs!Category
dblTar = rs!Data
Do While Not rs.EOF
If rs!Category = strCat Then
dblTar = 1 / (rs!Data * dblTar)
rs.Edit
rs!Target = dblTar
rs.Update
rs.MoveNext
Else
strCat = rs!Category
dblTar = rs!Data
End If
Loop
End Sub

Display Another Data from Other Field if the Data is Empty

Hello Everyone Good Afternoon,
I have 5 Fields in MySQL and there are:
ItemCode
Description
OrderQty
ApprovedQty
UoM
UnitPrice
Total
I cant explain it using proper words but I hope you will understand it by letting me show to you the table.
_______________________________________________________________
|ItemCode|Description|OrderQty|ApprovedQty|UOM|UnitPrice|Total|
---------------------------------------------------------------
|12345678|Ketchup |12.00 |0.00 |PC |1.00 |12.00|
|67891111|Soy Sauce |0.00 |12.00 |PC |1.00 |12.00|
---------------------------------------------------------------
Now you see it, I hope you can understand it now.
Here is my Question, I have a Code that will transfer the Data above into a Datagridview but theres a twist and that twist is the Question.
Here it is:
How can I Display the Data like this; If ApprovedQty is 0.00 then the Data in the OrderQty will display but if ApprovedQty is not 0.00 regardless of what data is in the OrderQty the ApprovedQty will be Show.
Something like this.
Based on the Table above
___________________________________________________
|ItemCode|Description|OrderQty|UOM|UnitPrice|Total|
---------------------------------------------------
|12345678|Ketchup |12.00 |PC |1.00 |12.00|
|67891111|Soy Sauce |12.00 |PC |1.00 |12.00|
---------------------------------------------------
Here is my code but it only shows the Approved Qty
Private Sub loadfinalpurch1()
Dim con1 As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=inventory")
Dim sql1 As MySqlCommand = New MySqlCommand("Select ItemCode,Description,ApprovedQty,UoM,UnitPrice,Total from final_purch where PRnumber = '" & Label2.Text & "' and Added is NULL OR Added ='';", con1)
Dim ds1 As DataSet = New DataSet
Dim adapter1 As MySqlDataAdapter = New MySqlDataAdapter
con1.Open()
adapter1.SelectCommand = sql1
adapter1.Fill(ds1, "MyTable")
DataGridView1.DataSource = ds1.Tables(0)
con1.Close()
With DataGridView1
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Item Code"
.Columns(1).HeaderCell.Value = "Description"
.Columns(2).HeaderCell.Value = "Order Qty"
.Columns(3).HeaderCell.Value = "UOM"
.Columns(4).HeaderCell.Value = "Unit Price"
.Columns(5).HeaderCell.Value = "Total Amount"
End With
DataGridView1.Columns.Item(0).Width = 90
DataGridView1.Columns.Item(1).Width = 200
DataGridView1.Columns.Item(2).Width = 90
DataGridView1.Columns.Item(3).Width = 90
DataGridView1.Columns.Item(4).Width = 100
DataGridView1.Columns.Item(5).Width = 100
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomCenter
Dim checkBoxColumn As New DataGridViewCheckBoxColumn()
checkBoxColumn.HeaderText = "Tag"
checkBoxColumn.Width = 30
checkBoxColumn.Name = "checkBoxColumn"
DataGridView1.Columns.Insert(0, checkBoxColumn)
End Sub
I hope you get my point.Do I have something to do with the MYSQL Command? with My Code? I don`t know how to achieve this.
TYSM For Future Help
You don't do that condition anywhere, you could do it on your code or directly changing your query:
Select ItemCode,
Description,
IF(ApprovedQty = 0, OrderQty, ApprovedQty) as myApprovedQty,
UoM,
UnitPrice,
Total from final_purch where PRnumber = '" & Label2.Text & "' and Added is NULL OR Added ='';", con1
You should implement this in your SQL using a case statement.
https://dev.mysql.com/doc/refman/5.7/en/case.html
The above answers using the IF() function are correct, but in my opinion it is better to use the CASE-WHEN so as to match other database engines like Microsoft SQL Server and Oracle.
SELECT
ItemCode,
Description,
IF (ApprovedQty = 0, OrderQty, ApprovedQty),
UoM,
UnitPrice,
Total
FROM table

generate random alphanumeric key in Ms. Access

by having this code on VB Script
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ltr, rNum, AlphaLtrs, selLtr
If Not Intersect(Target, Me.Columns(2)) Is Nothing And _
Target.Cells.Count = 1 Then
If Target.Value = "" Then
AlphaLtrs = "ABCDEFGHIGKLMNOPQRSTUVWXYZ"
selLtr = Application.RoundUp(Rnd() * 26, 0)
ltr = Mid(AlphaLtrs, selLtr, 1)
rNum = Application.RoundUp(Rnd() * 999999, 0)
Target.Value = Me.Range("A" & Target.Row) & "-" & ltr & rNum
End If
End If
End Sub
I need to create it through Ms. Access, Generally for Stock Keeping Products
Ms Access Table Contains this Fields
ID [Primary Key]
Product Title [Short text]
Type [Short text]
SKU [Short text]
Image Preview [Attachment]
Price [Number]
Availability [yes/No]
what i need is SKU will be auto Generate Keys for any new Product, Unique Key, may be by a button on form while inserting a new entry or may be by initially new entry , Key will be same as the Excel Code e.g. Z401374 (alpha numeric) and once Generated cant be change
Drop this into a module and run it. You should get what you need.
Sub test()
Dim s As String * 7 'fixed length string with 7 characters
Dim n As Integer
Dim ch As Integer 'the character
For n = 1 To Len(s) 'don't hardcode the length twice
Do
ch = Rnd() * 127 'This could be more efficient.
'48 is '0', 57 is '9', 65 is 'A', 90 is 'Z', 97 is 'a', 122 is 'z'.
Loop While ch < 48 Or ch > 57 And ch < 65 Or ch > 90 And ch < 97 Or ch > 122
Mid(s, n, 1) = Chr(ch) 'bit more efficient than concatenation
Next
Debug.Print s
End Sub
What you'll probably then have to do is do an INNER JOIN on your table (or SELECT SKU from tblProducts WHERE SKU = "the above generated string") to make sure it didn't randomly generate the same string twice. Eventually, with enough SKUs, that will happen. If it did, just re-run the generator and test again until you don't find a match, and then you know you have a unique SKU.

Access VBA giving incorrect results when comparing two numbers

I have a table linked to a form where a user enters an ISBN number. I'm checking to make sure the ISBN is valid. However, when I get to a point where I need to compare two numbers, I am incorrectly told that they do not match, when they definitely do match.
Private Sub isbn_BeforeUpdate(Cancel As Integer)
Dim isbn As String
Dim cleanIsbn As Double
Dim onlyIsbn As Double
Dim checkDigit As Integer
Dim legnth As Integer
length = 0
isbn = Forms!frmPubInfo!isbn.Value
' Strip out all hyphens
For i = 1 To Len(isbn)
Dim ch As String
ch = Mid(isbn, i, 1)
If IsNumeric(ch) Then
length = length + 1
Dim num As Integer
num = CInt(ch)
cleanIsbn = (cleanIsbn * 10) + num
End If
Next
' Check if 13 numbers
If length = 13 Then
Dim xBy3 As Boolean
Dim total As Integer
Dim calcCheckDigit As Integer
total = 0
xBy3 = False
' Calculate total amount
For j = 1 To 12
ch = Mid(cleanIsbn, j, 1)
If xBy3 = True Then
total = total + (ch * 3)
xBy3 = False
Else
total = total + ch
xBy3 = True
End If
Next
' Get calculated check digit
calcCheckDigit = 10 - (total Mod 10)
' Extract check digit
checkDigit = Mid(cleanIsbn, 13, 1)
' Debug output
MsgBox ("Actual CheckDigit: " & checkDigit & vbNewLine & _
"Calculated CheckDigit: " & calcCheckDigit)
' Check if check digit and calculated check digit match
If checkDigit <> calculatedCheckDigit Then
MsgBox ("checkDigit and calcCheckDigit are not the same")
Else
MsgBox ("They match! ISBN is good!")
End If
Else
' Display error
MsgBox ("Not enough numbers!")
End If
End Sub
When I get down to the 'Check if check digit and calculated check digit match', the If statement always says they don't match, even though the debug output above gives me the same two numbers.
I have tried:
Declaring the checkDigit variables as strings.
Casting the checkDigit variables as strings in the If Statement with CStr.
Casting the checkDigit variables as Integers in the If Statement with CInt.
I initially thought it was an issue with the data types, but if I'm casting them to the same type right as I'm comparing them, that can't be the issue, right?
This is all using Access 2013.
Man... I can't believe I didn't see this at first. I tested your code and got similar results as you. After looking at it closer I noticed that the if statement was wrong. In short you need to use Option Explicit and this error would have been caught. Option Explicit ensures that all variables are declared. In not an error is thrown.
You statement contains a null
If checkDigit <> calculatedCheckDigit Then
You dont have a variable called calculatedCheckDigit it should be calcCheckDigit.
If checkDigit <> calcCheckDigit Then
Just a side note: Your code for stripping out the hyphens obviously works but I offer this tweak.
' Dim as string since it is treated as one with Mid anyway.
' In practice Len didnt give accurate results while it was Double.
Dim cleanIsbn As String
' Strip out all hyphens
cleanIsbn = Replace(isbn, "-", "")
' Check if 13 numbers
If (Len(cleanIsbn) = 13) And IsNumeric(cleanIsbn) Then
' Process Stuff
Else
' Display error
MsgBox "Does not appear to be a valid ISBN value!"
End If
Take the isbn and just remove the hyphens with a replace. After that change if the result cleanIsbn is 13 characters long and numeric then you can assume its a good value to process.
ISBN Reference
I had to look it up but the math behind the ISBN numbers is located for reference here

MS ACCESS - Hierarchical tree sort

I'm struggling with a sorting problem.
I've got a table which is as follows:
aspect_id (int)
aspect_text (memo)
root_id (int) which has as a foreign key a aspect_id
I've got a non cyclic tree with the following dummy data:
aspect_id aspect_text root_id
1 root null
2 aspect1 1
3 aspect2 1
4 aspect3 2
5 aspect5 4
In the example the data is sorted correctly, in my database its not. I want to sort that it starts at the root element, then finds a child, output that child and does that recursively.
With CTE it is fairly doable. Access doesn't support this. With CTE it would be something like:
WITH aspectTree (aspect_id, root_id, Level#) AS
(
Select
aspect.aspect_id,
aspect.root_id,
0
FROM aspect
WHERE aspect.aspect_id = 44
UNION ALL
SELECT
aspect.aspect_id,
aspect.root_id,
T.Level# + 1
FROM aspect
INNER JOIN aspectTree AS T
On T.aspect_id = aspect.root_id
)
SELECT * FROM aspectTree;
If performance is not a consideration, this fairly simple solution would work:
Public Function GetLevel(ByVal lngNodeId As Long) As Long
Dim varRootId As Variant
varRootId = DLookup("root_id", "aspect", "aspect_id=" & lngNodeId)
If IsNull(varRootId) Then
GetLevel = 0
Else
GetLevel = GetLevel(varRootId) + 1
End If
End Function
You could then use that function in your ORDER BY clause:
SELECT aspect.*
FROM aspect
ORDER BY GetLevel([aspect_id]), aspect_text
I don't know if the following will work for you but here you go using Bill of Materials algorithms.
Bill Of Materials
BOM, with Joe Celko Nested Sets
Its full of test code, but i did something that works in vb code. Its really ugly and slow, but it works. Im now cleaning it up, just got it working. The solution is a recursive function. The function calls on itself if it finds that the node has childs. It seemed to overwrite the arrays, that why its an array of arrays. The code is hideous, but it works and thats all i needed. The database is and will stay small (<1000 records) so speed is not an issue. Thanks for the comments and answers, if someones knows i better solution, i would love to hear it.
Private Function Fillarray(value As Integer)
Dim done As Boolean
j = j + 1
esql = "select aspect_id from aspect where root_id = " & value
Set rec(j) = db.OpenRecordset(esql)
Dim k As Integer
k = j
Do While Not rec(k).EOF
done = True
arra(i) = rec(k).Fields(0)
Dim temp1 As String
temp1 = DLookup("[aspects]", "[aspect]", "[aspect_id] = " & rec(k).Fields(0))
db.Execute "INSERT INTO sortedaspect (aspect_id, aspect) VALUES (" & rec(k).Fields(0) & ", '" & temp1 & "')"
esql = "select aspect_id from aspect where root_id = " & rec(k).Fields(0)
Set rec(90) = db.OpenRecordset(esql)
Do While Not rec(90).EOF And done
'fix this without a loop,you only need to know if it has childs...
Fillarray (rec(k).Fields(0))
done = False
Loop
'next child
rec(k).MoveNext
'value = arra(i)
i = i + 1
'MsgBox arra(i - 1)
Loop
End Function