Hello Access aficionados.
In the following code to add an article to a purchase order line table and then open the form on the purchase order in question , I had to open the window “frmPurchase” twice in succession. If I omit the first docmd.openform statement, the form would open at the first record in the table, not the one defined in the where clause “PUOpen and PUCompID = “ & Me.lstCompany.
I had noticed previously that, when the form “frmPurchase” was already open, Access went to the correct record, and not if the calling program had to open the window, which is why I came up with the idea of replicating this behavior in the code.
Is this normal behavior, and if not, how can I improve the code?
Thanks in advance for solving the mystery.
In the following code to add an article to a purchase order line table and then open the form on the purchase order in question , I had to open the window “frmPurchase” twice in succession. If I omit the first docmd.openform statement, the form would open at the first record in the table, not the one defined in the where clause “PUOpen and PUCompID = “ & Me.lstCompany.
I had noticed previously that, when the form “frmPurchase” was already open, Access went to the correct record, and not if the calling program had to open the window, which is why I came up with the idea of replicating this behavior in the code.
Code:
With rstC
.FindLast "PULineNB <> 0 AND PuLineHeadingID = " & rstB!PUID
If Not .NoMatch Then
linenb = rstC!PULineNb
Else
linenb = 0
End If
rstC.AddNew
rstC!PuLineHeadingID = rstB!PUID
rstC!PuLineArtno = Me!frmNomenclatuurSubfrm.Form.Artno
rstC!PULineNb = linenb + 1
rstC.Update
End With
DoCmd.OpenForm "frmPurchase"
DoCmd.OpenForm "frmPurchase", acNormal, , "PUOpen AND PUCompID = " & Me.lstCompany
Is this normal behavior, and if not, how can I improve the code?
Thanks in advance for solving the mystery.
Last edited by a moderator: