B
BruceM
I have a Purchase Order form with a LineItems subform (record sources are a
main PO table and a LineItems child table). The line items are selected
from a combo box based on a products table (tblPO_Product). The information
includes ProductCode, ProductDescription, Unit (Each, Case, etc.), and
UnitPrice. There need to be the ability to edit the Unit on the fly.
Sometimes the unit information is incorrect ("Each" where it should be
"Case", or something like that). If it reads "Each" and the user changes it
to "Case", a message appears asking whether the item is to be changed for
all records or for this record only. This is the code in txtUnit, the text
box bound to the Unit field.
It works, but not the curiosity in the lline after the asterisks: vbYesNo,
with vbOK as the response. I stumbled upon this as I was attemting to get
rid of a "This record has been changed by another user" message. When I use
it as is the code works as intended. If I change it to vbYes (the "correct"
wording) I get the error message.
I have similar code to change the unit price, with no problems. I can post
it, if it helps.
I guess I could use Cancel = True rather than Exit Sub shortly after the If
Err line.
Anyhow, this has me stumped. I am the only user, but am getting the error
message unless I do this weird bit of coding.
Private Sub txtUnit_BeforeUpdate(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strUnit As String, strDescr As String, strMsg As String, strTitle As
String
Set db = CurrentDb
strUnit = Me.txtUnit.Text
strDescr = Me.cboDescription.Column(0)
strMsg = "Do you want to change the Unit to """ & strUnit & """" & vbCrLf
& _
"for future selections of " & strDescr & "?" & vbCrLf & _
"(Click ""No"" to apply the change to this record only.)"
strTitle = "Change Unit Description?"
' ******* Anomaly here
If MsgBox(strMsg, vbYesNo, strTitle) = vbOK Then
Set rs = db.OpenRecordset("tblPO_Product", dbOpenDynaset)
On Error Resume Next
rs.MoveFirst
rs.FindFirst "ProductID = " & Me.cboDescription
rs.Edit
rs!ProdUnit = strUnit
If Err Then
MsgBox "Error #" & Err.Number & " (" & Err.Description & _
") txtUnit_BeforeUpdate in frmPO, fsubPO_Items"
rs.Close
Exit Sub
End If
rs.Update
rs.Close
End If
End Sub
main PO table and a LineItems child table). The line items are selected
from a combo box based on a products table (tblPO_Product). The information
includes ProductCode, ProductDescription, Unit (Each, Case, etc.), and
UnitPrice. There need to be the ability to edit the Unit on the fly.
Sometimes the unit information is incorrect ("Each" where it should be
"Case", or something like that). If it reads "Each" and the user changes it
to "Case", a message appears asking whether the item is to be changed for
all records or for this record only. This is the code in txtUnit, the text
box bound to the Unit field.
It works, but not the curiosity in the lline after the asterisks: vbYesNo,
with vbOK as the response. I stumbled upon this as I was attemting to get
rid of a "This record has been changed by another user" message. When I use
it as is the code works as intended. If I change it to vbYes (the "correct"
wording) I get the error message.
I have similar code to change the unit price, with no problems. I can post
it, if it helps.
I guess I could use Cancel = True rather than Exit Sub shortly after the If
Err line.
Anyhow, this has me stumped. I am the only user, but am getting the error
message unless I do this weird bit of coding.
Private Sub txtUnit_BeforeUpdate(Cancel As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strUnit As String, strDescr As String, strMsg As String, strTitle As
String
Set db = CurrentDb
strUnit = Me.txtUnit.Text
strDescr = Me.cboDescription.Column(0)
strMsg = "Do you want to change the Unit to """ & strUnit & """" & vbCrLf
& _
"for future selections of " & strDescr & "?" & vbCrLf & _
"(Click ""No"" to apply the change to this record only.)"
strTitle = "Change Unit Description?"
' ******* Anomaly here
If MsgBox(strMsg, vbYesNo, strTitle) = vbOK Then
Set rs = db.OpenRecordset("tblPO_Product", dbOpenDynaset)
On Error Resume Next
rs.MoveFirst
rs.FindFirst "ProductID = " & Me.cboDescription
rs.Edit
rs!ProdUnit = strUnit
If Err Then
MsgBox "Error #" & Err.Number & " (" & Err.Description & _
") txtUnit_BeforeUpdate in frmPO, fsubPO_Items"
rs.Close
Exit Sub
End If
rs.Update
rs.Close
End If
End Sub