Hi I have this code which i thought was perfect maybe a bit of a mess but it works. The only problem is that the rst!PONo does not look at the table properly and generate a continuing number, which i fine but i would prefer it to fill in the blanks plus carryon from the last record in the table. Also the last problem is that assigning this PONo to relevant records within a loop procedures works sometimes and then doesn't. Here is the code:
When assigning the PONO to the ordlin table, it assigns this value for half the order and then decides to stop for some unknown reason. Can you see a problem with my coding?
Code:
Dim db As Database
Dim rst As Recordset
Dim rst2 As Recordset
Dim rst3 As Recordset
Dim IntPONo As Integer
Dim strSQL As String
Dim PO As String
DoCmd.SetWarnings False
Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT * FROM pordhdr")
If IsNull(txtSuppNo) Then
MsgBox "You CANNOT Assign an Automatic Purchase Order when there are NO SUPPLIER Or ORDER Details.", vbOKOnly, "Criteria Missing"
Else
rst.Edit
strSQL = "INSERT INTO pordhdr ([SuppNo],[PODate],[DueDate]) SELECT forms!frmPOGenerator!txtSuppNo AS SuppNo,[OrderDate],[DueDate] FROM ordhdr WHERE ordhdr.OrderNo = forms!frmPOGenerator!txtOrderNo"
DoCmd.RunSQL strSQL
rst.update
rst.Close
Set rst3 = db.OpenRecordset("SELECT * FROM pordhdr")
rst3.MoveLast
PO = MsgBox("Purchase Order " & rst3!PONo & " Has Been Created. ", vbOKOnly, "Purchase Order Created")
rst3.Close
Set rst3 = Nothing
Set rst3 = CurrentDb.OpenRecordset("SELECT * FROM pordhdr")
rst3.MoveLast
Set rst2 = db.OpenRecordset("SELECT * FROM ordlin")
rst2.Edit
strSQL = "UPDATE ordlin SET [PONo] = '" & rst3!PONo & "' WHERE ([ordlin.OrderNo] = [forms]![frmPOGenerator]![txtOrderNo] And [ordlin.SuppNo] = [forms]![frmPOGenerator]![txtSuppNo])"
DoCmd.RunSQL strSQL
rst2.update
rst2.Close
rst3.Close
Set rst2 = Nothing
Set rst3 = Nothing
DoCmd.SetWarnings True
lstSuppNoSelect.Requery
End If
Comment