Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run update query many time for each item number?? 2

Status
Not open for further replies.

afekri

Programmer
Apr 7, 2009
15
Hi,

I have a table include Item numbers and names ,...
and also another table which is Quantity in and Quantity Out and Quantity in Stock.

I have a Update query which will recalculate the quantity in stock for one item number which i put in criteria.

I have to run this update query one by one for all the item numbers which is in the first table..

How can I do?? Please help me..

Thanks for any idea..
Ali
 
Code:
RS.Edit 'can be implied (left out) with ADO Recordset; Required for DAO
RS!FieldName = [i]<value>[/i]
RS.Update
 
It's new things for me.

I have to use these lines in the query?? or in the vba??

I think to be used in vba but....

for example::

if recordset in vba is in record 4:
[item number]=27
[location]=3

so my query criteria in this time to be these values!!!

How query can get these data from VBA??

Thanks
Ali
 
Recordsets are VBA.

One way to run SQL in VBA is the RunSQL method of the Docmd object. strSQL is an SQL string...


Code:
Docmd.RunSQL strSQL

I still believe what you want to do can be done in a query.
 
Ok, Thanks to all ...

I used all of your advise and made this:

Dim a As String
Dim rs As New ADODB.Recordset
rs.Open "Select * FROM Inventory", CurrentProject.Connection, adOpenStatic, adLockReadOnly
rs.MoveFirst
Do Until rs.EOF
With rs
a = rs!ItemNumber
End With
DoCmd.RunSQL "INSERT INTO [Inventory items] ( [Item Number] ) SELECT Inventory.ItemNumber FROM Inventory WHERE (((Inventory.ItemNumber)=a));"


rs.MoveNext
Loop


But, I don't know why "itemnumber" value not save to "a" to make append correctly!!!

Please help me to correct it then this thread will close for me.

Thanks again to all.
Ali
 
Code:
DoCmd.RunSQL "INSERT INTO [Inventory items] ( [Item Number] ) SELECT Inventory.ItemNumber" & _ 
" FROM Inventory WHERE (((Inventory.ItemNumber)= " & a & "));"
 
Special Thanks to lameid and lespaul....

Finally I found what I need and many thanks to all.
 
I still say this should be all you need... no where no loop.

Code:
DoCmd.RunSQL "INSERT INTO [Inventory items] ( [Item Number] ) SELECT Inventory.ItemNumber" & _ 
" FROM Inventory"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top