Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Event Procedure not Working Correctly ->Need HELP

Status
Not open for further replies.

quest4

Technical User
Joined
Aug 27, 2001
Messages
735
Location
US
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.
 
The code below doesn't do anything to the table, it just updates the Temp variables


Code:
                    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")


you need to replace

Temp2 = rs.Fields("ID")

with

rs.Fields("ID") = Temp2

to save the value back to the database.

 
Thank you for the response, jjob. I already tried that and then some. Igot it amount working except I could never get the undo/cancel to work right. Do to a dead line, today, I was forced to use a different tack. I have it almost working now but I need to know how to word one thing on the OnKeyDown event: When CRTL-b is pressed then a small procedure. Thank you again for the response, I hate dead lines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top