Hi I am trying to insert certain information into a table based on a unique id. In terms of the Data Environment, it is within Stock and BOM Details. I have enforced a Button to do this command however it only works on 1 row at a time instead of moving onto the next, which i have coded it too. Can anyone tell me why or how to fix this issue. I can't keep clicking on the different rows followed by the button.
I am using Microsoft Access 2007:
With this coding i receive no error however it removes the StkShortDesc and Price from the actual fields and still only displays data for the first row. I have checked books and the internet forums, to my point of view this code should work however it doesn't. Any help would be much appreciated!
Thanks
Chris
I am using Microsoft Access 2007:
Code:
Dim Reply As String Dim strSQL As String Dim strSQL2 As String Dim db As Database Dim rst As Recordset strSQL = "INSERT INTO stkmas ([StkShortDesc],[Width],[Depth],[Height]) SELECT [StkShortDesc],[Width],[Depth],[Height] FROM preordlin WHERE IsNull(StkID)" strSQL2 = "INSERT INTO preordlin ([OrderNo],[StkID],[StkShortDesc],[Width],[Depth],[Height],[Qty]) SELECT forms!frmCustomerOrderForm!sfrmSOHeader!OrderNo AS OrderNo,[SubStkID],[stkmas.StkShortDesc],preordlin.Width,preordlin.Depth,preordlin.Height,[Qty] FROM (stkbommas INNER JOIN stkmas ON stkbommas.substkID = stkmas.StkID) WHERE stkbommas.StkID = forms!frmPreSOLine!StkID" StkID.value = DLookup("[StkID]", "stkmas", "[StkShortDesc] = Forms![frmPreSOLine]![StkShortDesc]") Price.value = DLookup("[SalePrice1]", "primas", "[StkID] = Forms![frmPreSOLine]![StkID]") If IsNull(StkID) Then Reply = MsgBox("There are Stock Items present that do not belong to our existing Stock files. Would you like to ADD them?", vbYesNo, "None Existent Stock Details!") If Reply = vbYes Then DoCmd.RunSQL strSQL Else End If Else End If [B] DoCmd.SetWarnings False Set db = CurrentDb() Set rst = db.OpenRecordset("SELECT * FROM preordlin") Do Until rst.EOF rst.Edit DoCmd.RunSQL strSQL2 rst.Update rst.MoveNext Loop Until rst.EOF rst.Close Me.Requery Set rst = Nothing DoCmd.SetWarnings True[/B]
Thanks
Chris
Comment