Forum Moderators: open
Sorry it's a bit ugly but these forums aren't really designed to insert code snippets, but hopefully this should you out a little. And before anyone asks the first line is an alternative to using the adovbs.inc file...
This is just an ugly cludge of code which gets each fictional test user, then retrieves all their transaction names and then write them out into their user record in sequence. But it does access two tables at once and writes some data back.
<!-- METADATA TYPE="TypeLib" FILE="C:\Program Files\Common Files\System\ADO\MSADO15.dll" -->
<%
Dim conDB, rstA, rstB
Dim sSQLSet conDB = Server.CreateObject("ADODB.Connection")
Set rstA = Server.CreateObject("ADODB.Recordset")
Set rstB = Server.CreateObject("ADODB.Recordset")'Outer loop
sSQL = "SELECT ID, Name FROM TonyUsers WHERE TestUser = 1"
rstA.Open sSQL, conDB, adOpenForwardOnly, adLockReadOnly
Do Until rstA.EOF'Inner loop
sSQL = "SELECT MyReference FROM TonyUsers_Orders WHERE UserID = " & rstA("ID").Value
rstA.Open sSQL, conDB, adOpenForwardOnly, adLockReadOnly
Do Until rstB.EOFsSQL = "UPDATE TonyUsers SET Notes = Notes + '" & rstB("MyReference") & ", ' WHERE ID = " & rstA("ID").Value
conDB.Execute sSQLrstB.MoveNext
Loop
rstB.ClosesSQL = "UPDATE TonyUsers SET Notes = LEFT( Notes, LEN( Notes ) - 2 ) WHERE RIGHT( Notes, 2 ) = ', ' AND ID = " & rstA("ID").Value
conDB.Execute sSQLrstA.MoveNext
Loop
rstA.CloseSet rstB = Nothing
Set rstA = Nothing
Set conDB = Nothing
%>
- Tony