C
Coldeyes
I have a form where the user enters new purchase orders. Since clients send
lots of modifications for existing orders, PO numbers have to be checked
whether already in the table or not. I wrote this code:
Private Sub PONumber_AfterUpdate()
'checks whether purchase order really new or not
'if not opens old record for modification
Dim db As Database
Dim rs As Recordset
Dim cond As String
Dim Msg, Style, Title, Response
'opens table
Set db = CurrentDb
Set rs = db.OpenRecordset("PurchaseOrders", dbOpenDynaset)
'gives the condition for the search which is the po number the user entered
cond = Me.PONumber
'sets the message
Msg = "This purchase order number is already registered. Do you wish to
modifiy the record?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Existing order number"
'searches for the order number entered
rs.MoveFirst
Do Until rs.EOF
If rs!PONumber = cond Then
Response = MsgBox(Msg, Style, Title)
If Response = 6 Then 'user pushed yes
DoCmd.RunCommand acCmdUndo 'cancels the number entered
DoCmd.ApplyFilter , "PONumber = cond" 'displays old record
etc.
The problem is that instead displaying the existing record a panel pops up
and asks the user to enter the parameter cond. While debugging it became
clear that the code knows the value of cond.
What can be wrong?
Thanks in advance for your help
lots of modifications for existing orders, PO numbers have to be checked
whether already in the table or not. I wrote this code:
Private Sub PONumber_AfterUpdate()
'checks whether purchase order really new or not
'if not opens old record for modification
Dim db As Database
Dim rs As Recordset
Dim cond As String
Dim Msg, Style, Title, Response
'opens table
Set db = CurrentDb
Set rs = db.OpenRecordset("PurchaseOrders", dbOpenDynaset)
'gives the condition for the search which is the po number the user entered
cond = Me.PONumber
'sets the message
Msg = "This purchase order number is already registered. Do you wish to
modifiy the record?"
Style = vbYesNo + vbCritical + vbDefaultButton2
Title = "Existing order number"
'searches for the order number entered
rs.MoveFirst
Do Until rs.EOF
If rs!PONumber = cond Then
Response = MsgBox(Msg, Style, Title)
If Response = 6 Then 'user pushed yes
DoCmd.RunCommand acCmdUndo 'cancels the number entered
DoCmd.ApplyFilter , "PONumber = cond" 'displays old record
etc.
The problem is that instead displaying the existing record a panel pops up
and asks the user to enter the parameter cond. While debugging it became
clear that the code knows the value of cond.
What can be wrong?
Thanks in advance for your help