I have a procedure, in the form's BeforeInsert event, to put ItemNumbers on PartNumbers entered into a subform. It works fairly well. I have another procedure, in the PartNumber's textbox Before Update event, and it is not working correctly. The undo is working correctly and the the setting of the ItemNumber to blank is working correctly. I have a table, tblCallID, which has one field in it, ID, which is the last number entered into ItemNumber on the subform. I am trying to reduce that number, tblCAllID!ID, by one and this is the main part of what is wrong. Here is the procedure:
Private Sub PartNumber_BeforeUpdate(Cancel As Integer)
If DCount("[variable_fields_1]", "dbo_hnymastr", "[part_number]='" & Me.PartNumber & "'"
= 0 Then
If MsgBox("Warning: The Part Number you entered in Invalid. Is it a Reference Item?", vbYesNo) = vbYes Then
Me!Standard = "RF"
'If Yes, enter RF in Standard
Else
Cancel = True
Me.Undo
'If No, Undo record
Me!ItemNumber = ""
'Set ItemNumber = ""
Dim db As Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCallID_BOM"
rs.MoveFirst 'this moves to the first record to insure we are getting the correct number
rs.Edit
'edit the record
Temp1 = rs.Fields("ID"
'set a temporary variable to the last number
Temp2 = Temp1 - 1
'subtract one from it
Temp2 = rs.Fields("ID"
'take the add on to it ands stuff it back in the table
rs.Update
'update record
rs.Close
'close it up
db.Close
End If
End If
End Sub
I use a procedure almost exactly the same, from the Dim db line on, to control the incrementing of the ItemNumbers on the subform, except I use Temp2=Temp1+1. Fore some reason when I run the above code the tblCallID!ID number is increasing by one instead of decreasing by. Any ideas on WHY? I have a bad feeling the the BeforeInsert event procedure is being used instead of the the above code, but again, WHY? This is so close to being done that it isn't even funny. I hope that someone will show me the error of my ways, so I can finish this off. I have to have it working, to demo it to my boss and the senior staff, on Friday. Thank you very much to an kind person rendering assistance to me on this problem.
Private Sub PartNumber_BeforeUpdate(Cancel As Integer)
If DCount("[variable_fields_1]", "dbo_hnymastr", "[part_number]='" & Me.PartNumber & "'"

If MsgBox("Warning: The Part Number you entered in Invalid. Is it a Reference Item?", vbYesNo) = vbYes Then
Me!Standard = "RF"
'If Yes, enter RF in Standard
Else
Cancel = True
Me.Undo
'If No, Undo record
Me!ItemNumber = ""
'Set ItemNumber = ""
Dim db As Database, rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblCallID_BOM"

rs.MoveFirst 'this moves to the first record to insure we are getting the correct number
rs.Edit
'edit the record
Temp1 = rs.Fields("ID"

'set a temporary variable to the last number
Temp2 = Temp1 - 1
'subtract one from it
Temp2 = rs.Fields("ID"

'take the add on to it ands stuff it back in the table
rs.Update
'update record
rs.Close
'close it up
db.Close
End If
End If
End Sub
I use a procedure almost exactly the same, from the Dim db line on, to control the incrementing of the ItemNumbers on the subform, except I use Temp2=Temp1+1. Fore some reason when I run the above code the tblCallID!ID number is increasing by one instead of decreasing by. Any ideas on WHY? I have a bad feeling the the BeforeInsert event procedure is being used instead of the the above code, but again, WHY? This is so close to being done that it isn't even funny. I hope that someone will show me the error of my ways, so I can finish this off. I have to have it working, to demo it to my boss and the senior staff, on Friday. Thank you very much to an kind person rendering assistance to me on this problem.