B
BruceM
I have a standard Purchase Order database, with a main PurchaseOrder table
(tblPO) and a related line items table (tblPO_Items). These are represented
to the user as a form/subform.
There is a Products table (tblPO_Product), listing products according to
Supplier, Description, Code, Unit, and Unit Price. Unit Price may be Null.
There is a combo box on the Line Items subform that gets it Row Source from
tblPO_Products. If the product is not in the drop-down list, the Not In
List event opens a pop-up form on which the user can fill in the
information. When that is done there is a button to run the following code.
The code inserts a new record into tblPO_Product, then grabs the key field
from the new record and inserts a record into tblPO_Items (the Line Items
subform table).
I don't know if this is the best way to go about this, but it works in terms
of inserting the new record into tblPO_Products, and inserting a new record
into tblPO_Items. The missing piece is that the new record cannot be seen
right away on the Line Items subform. If I navigate away from the PO
record, then back to it, the item is there. However, I have so far failed
in all of my attempts to refresh the subform, save the record, or by some
means accomplish what occurs when I navigate away from, then back to the
record.
It is likely I won't see reponses to this thread until Monday, so if I do
not acknowledge replies until then please do not think me rude.
varUnitPrice = Nz(Me.txtNewUnitPrice, "Null")
strDelim = Chr(34)
strNewDescr = strDelim & Me.txtNewDescr & strDelim
strNewCode = strDelim & Me.txtNewCode & strDelim
strNewUnit = strDelim & Me.txtNewUnit & strDelim
lngSuppID = Forms!frmPO!SupplierID
strSQL_NewProd = "INSERT INTO tblPO_Product (SupplierID, " & _
"ProdCode, ProdDescr, ProdUnit, UnitPrice)" & vbCrLf & _
"SELECT " & lngSuppID & ", " & _
strNewCode & ", " & strNewDescr & ", " & _
strNewUnit & ", " & varUnitPrice
DBEngine(0)(0).Execute strSQL_NewProd, dbFailOnError
lngNewProd = DLookup("ProductID", "tblPO_Product", _
"SupplierID = " & lngSuppID & _
" AND ProdCode = " & strNewCode & _
" AND ProdDescr = " & strNewDescr)
lngReqID = Forms!frmPO!ReqID
strSQL_NewLine = "INSERT INTO tblPO_Items (PO_ReqID, " & _
"ProductID, Quantity, UnitPrice)" & vbCrLf
& _
"SELECT " & lngReqID & ", " & _
lngNewProd & ", 1, " & varUnitPrice
DBEngine(0)(0).Execute strSQL_NewLine, dbFailOnError
(tblPO) and a related line items table (tblPO_Items). These are represented
to the user as a form/subform.
There is a Products table (tblPO_Product), listing products according to
Supplier, Description, Code, Unit, and Unit Price. Unit Price may be Null.
There is a combo box on the Line Items subform that gets it Row Source from
tblPO_Products. If the product is not in the drop-down list, the Not In
List event opens a pop-up form on which the user can fill in the
information. When that is done there is a button to run the following code.
The code inserts a new record into tblPO_Product, then grabs the key field
from the new record and inserts a record into tblPO_Items (the Line Items
subform table).
I don't know if this is the best way to go about this, but it works in terms
of inserting the new record into tblPO_Products, and inserting a new record
into tblPO_Items. The missing piece is that the new record cannot be seen
right away on the Line Items subform. If I navigate away from the PO
record, then back to it, the item is there. However, I have so far failed
in all of my attempts to refresh the subform, save the record, or by some
means accomplish what occurs when I navigate away from, then back to the
record.
It is likely I won't see reponses to this thread until Monday, so if I do
not acknowledge replies until then please do not think me rude.
varUnitPrice = Nz(Me.txtNewUnitPrice, "Null")
strDelim = Chr(34)
strNewDescr = strDelim & Me.txtNewDescr & strDelim
strNewCode = strDelim & Me.txtNewCode & strDelim
strNewUnit = strDelim & Me.txtNewUnit & strDelim
lngSuppID = Forms!frmPO!SupplierID
strSQL_NewProd = "INSERT INTO tblPO_Product (SupplierID, " & _
"ProdCode, ProdDescr, ProdUnit, UnitPrice)" & vbCrLf & _
"SELECT " & lngSuppID & ", " & _
strNewCode & ", " & strNewDescr & ", " & _
strNewUnit & ", " & varUnitPrice
DBEngine(0)(0).Execute strSQL_NewProd, dbFailOnError
lngNewProd = DLookup("ProductID", "tblPO_Product", _
"SupplierID = " & lngSuppID & _
" AND ProdCode = " & strNewCode & _
" AND ProdDescr = " & strNewDescr)
lngReqID = Forms!frmPO!ReqID
strSQL_NewLine = "INSERT INTO tblPO_Items (PO_ReqID, " & _
"ProductID, Quantity, UnitPrice)" & vbCrLf
& _
"SELECT " & lngReqID & ", " & _
lngNewProd & ", 1, " & varUnitPrice
DBEngine(0)(0).Execute strSQL_NewLine, dbFailOnError