I only want this code to fire when I've entered a record.
Quote:
I'm not sure what it is you are trying to prevent/accomplish with the above quoted statement.
I tried not to include too much information, but it looks like I entered too little. I'll try again.
I have a data entry from. You fill in the boxes, when your done the form flips to a new records, just like normal and a new row ends up in tblTransactions . In addition to that I want to update a related record in tblData with information from the form. The easiest way I could see to do that is in the Before Update event.
Here is that code.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
strSQL = "Update tblData Set Status_ID = " & Me.txtStatus_ID
strSQL = strSQL & " Where Record_ID = " & Me.txtRecord_ID
If Not IsNull(Me.txtTransaction_Type) And Me.txtTransaction_Type = "1" Then
DoCmd.RunSQL strSQL
End If
End Sub
This may seem like much ado about nothing, but when I first open the form, then switch to Design Mode, the Before Update event runs and encounters this error:
"The expression you entered refers to an object that is closed and doesn't exist."
The code is hanging up on the first line of of the sub.
strSQL = "Update tblData Set Status_ID = " & Me.txtStatus_ID
If I dismiss that error I get a 2nd message saying "Access encountered an error trying to save this record. Do you want to close object anyway?"
I don't know why the Before Update event is even "firing" at this time. I only want to run this code when I enter a new record. This started out as a bigger problem, but I'd like to understand this. I'm afraid it might occur at some other time than design time.
Should I be using a different event?