using for loop in runSql

  • Thread starter Thread starter lonexOO
  • Start date Start date
L

lonexOO

Guest
Is it possible for me to use a for loop in runSql? I would like this to work after i push a print invoice button. Right now i have to manually go to another form and insert a new record in the table, but i have all the info I need to do it automatically (customerid, and invoiceid) from the invoice that was just generated from my form. I am used to programming ASP pages and I am not too familiar with VBA in access. I would like to do something like this...
select * from invoice where invoiceid = Forms!Orders!OrderID and invoiceTag=true; .....then I would like to run a for loop to insert a record into another table based on the quantity of the product purchaced using the information that i just got from the invoice table, something like this...
do while not eof or bof

for counter=1 to invoiceQuantity

'in ASP I would make database connection first of course and then

INSERT INTO tblwatercard (CustomerID, Cost,Date) VALUES ('" & invoiceCustomerID & "', '" & invoiceCost & "',#" & date &"#);"

next
recordsource.movenext
wend

I apologise for my limited programming skills. I know that if I was using a web form and ASP, I could get what I want but I am just out of my element at this point in Access. I hope I made sense.
thanks
ps thanks for the tip Jim on my last posting it sent me in the right direction
 
Here is a loop for you.....

Will open a recordset and delete and movenext until .EOF (end of file)

Dim DB As DAO.Database
Dim RS As DAO.Recordset

Set DB = CurrentDb
Set RS = DB.OpenRecordset("Select * FROM TableName WHERE OrderID = " & formOrderID)

With RS

Do Until .EOF
.Delete
.MoveNext
Loop

End With
 

Users who are viewing this thread

Back
Top Bottom