Hi all,
I have a macro in a Calc file that pulls info from a Base file which works well for me, however I am only pulling a single field from the query, all this does is pull a list of supplier from the base file and insert them into cells
This is the code I am using, I havent included the database connection part of it as I have no problem with that
Stmt = Conn.createStatement()
strSQL1 = " SELECT Supplier_Name from Suppliers where Active = 'Active' "
rem execute SQL statement;"
oResult = Stmt.executequery(strSQL1)
while oResult.next
outputvalue = oResult.getstring(1)
list = list+1
print outputvalue
Sheet = ThisComponent.Sheets(8)
Sheet.getCellByposition (6,list).setstring outputvalue
wend
what I need is to pull a second field from the database called ‘supplier_code’
I have tried altering the line below to include two fields but this only selects the first one
strSQL1 = " SELECT Supplier_Name, supplier_code from Suppliers where Active = 'Active' "
I then tried this below
strSQL1 = " SELECT Supplier_Name from Suppliers where Active = 'Active' "
oResult1 = Stmt.executequery(strSQL1)
while oResult1.next
outputvalue1= oResult1.getstring(1)
strSQL2 = " SELECT supplier_code from Suppliers where Supplier_Name = '" & outputvalue1 & "' "
oResult2 = Stmt.executequery(strSQL2)
while oResult2.next
outputvalue2 = oResult2.getstring(1)
print outputvalue1
print outputvalue2
list = list+1
Sheet = ThisComponent.Sheets(8)
Sheet.getCellByposition (6,list).setstring outputvalue1
Sheet.getCellByposition (5,list).setstring outputvalue2
wend
wend
This gives me “Type: com.sun.star.lang.DisposedException” error, but it does give me the firs record set and errors on the second.
If I take the second "while " and “wend” comands out I get “Unexpected symbol: End Sub.”
Next i tried with the “do” comand to make it loop insted of the wend.
Do
strSQL1 = " SELECT Supplier_Name from Suppliers where Active = 'Active' "
oResult1 = Stmt.executequery(strSQL1)
oResult1.next
outputvalue1= oResult1.getstring(1)
strSQL2 = " SELECT supplier_code from Suppliers where Supplier_Name = '" & outputvalue1 & "' "
oResult2 = Stmt.executequery(strSQL2)
oResult2.next
outputvalue2 = oResult2.getstring(1)
print outputvalue1
print outputvalue2
list = list+1
Sheet = ThisComponent.Sheets(8)
Sheet.getCellByposition (6,list).setstring outputvalue1
Sheet.getCellByposition (5,list).setstring outputvalue2
loop until outputvalue1 = ""
this did loop without errors but it only showed the first record set each time.
I did consider making two macros one for the supplier name and the second for the supplier code but I couldn’t be sure the records would be pulled in the same order.
I hope this makes sense to everyone
Any Ideas anyone?
Many Thanks Neil