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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeforeUpdate event stopping execution

Status
Not open for further replies.

csjoseph

MIS
Joined
Jan 2, 2001
Messages
247
Location
US
I have a form where I need to compare two values and modify another just prior to updating the record. I'm using this code to do this.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strCurLoc As String
Dim strStoreLoc As String

    txtCurLoc.SetFocus
    strCurLoc = txtCurLoc
    
    txtStoreLoc.SetFocus
    strStoreLoc = txtStoreLoc.Text
    
    If strStoreLoc = strCurLoc Then
        txtStatus.SetFocus
        txtStatus.Text = "IN"
        'lblStatus.Caption = "IN"
        'txtCurLoc.SetFocus
    Else
        txtStatus.SetFocus
        txtStatus.Text = "OUT"
        'lblStatus.Caption = "OUT"
        'txtCurLoc.SetFocus
    End If
    DoCmd.Save
End Sub

Problem is when I press a record navigation button the code is run but next record is not pulled up. Nav works fine unless I make a change that requires this code to be run. Also same situation I have a find button macro that does not work if I make change. I get 144 halt error.

Please help, thank you.
 
You may try to replace this:
DoCmd.Save
with this:
DoCmd.RunCommand acCmdSaveRecord

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
That changed what error I'm getting. Now the response is:


Run-time error '2115':

The Macro of function set to the beforeupdate or validationrule property for this field is preventing Microsoft Access from saving the data in the field.


What?
 
And what about simply this ?
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me!txtStoreLoc = Me!txtCurLoc Then
Me!txtStatus = "IN"
Else
Me!txtStatus = "OUT"
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Excellent work. That did it. I was doing the set focus thing because of Access telling me I could change object without focus. I'm going to dig into that a bit more but I'm working now.

Thanks a ton.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top