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

error with cancelling a db update

Status
Not open for further replies.

treyball3

Programmer
Jun 20, 2001
74
0
0
US
Ok, I'm using DAO and displaying a bound dbGrid on my form. Under certain circumstances, I need to cancel the transaction in the BeforeUpdate procedure. So, I use

Private Sub DBGrid1_BeforeUpdate(Cancel As Integer)
'code to determine if I need to do a cancel
Cancel = 1
End Sub

Ok, this does what I want, but I get the annoying "this action was cancelled by an associated object" error. There has to be a way from getting around this error message popping up right? Its very annoying to get and is not good for showing to our users. Does anyone know the best way to cancel a db transaction and NOT get this error??

Thanks in advance,
Todd



Thanks - Todd
 
Just a simple suggestion...

Maybe you could do:

Private Sub DBGrid1_BeforeUpdate(Cancel As Integer)
On Error GoTo Bad_Error
Cancel = 1
Bad_Error:
if err.Number = (whatever error number you receive) then err.Clear
End Sub

I'm not sure if this will work the way you want it to...but give it a try anyway

AIM: survivertiger
 
Thanks for the quick responses. I've tried both of these, but to no avail. The BeforeColUpdate event never fires for me, and I get no error number in the message box. I tried stopping the code and checking the err.number in the immediate window, but its set to 0. Any other ideas???




Thanks - Todd
 
Try doing "print err.source" in the immediate window when u get the error to see if it shows u the source...then u can do "if err.source = "whatever you get" then err.clear"

Just another thought....

AIM: survivertiger
 
Hmm...

When I get the error message, it doesn't have a number associated with it. I tried the err.source, no success there either.

The error isn't being thrown until the Exit Sub. If I remove that line, I still get the message, but not until the end of the DBGrid1_BeforeUpdate sub.

Basically, what I'm doing is testing what the user entered to be sure that its valid data. If its not, and they try to move off the row, then I need to move them back to that row, and tell them their data was incorrect. The only way I've found to get back to the original row is if I do a cancel of the db update. Maybe there's a better way? I don't think there's anyway to know what row you were previously on is there?? Ugh, this is kind of annoying because the only reason I have to do this is because of an error in Microsoft's combobox control. Windows XP and 2000 don't interpret the itemdata and text right if a certain scenario takes place.

Anyway, thanks for the responses, and hopefully someone has an answer to this.....



Thanks - Todd
 
Ok, thought I'd post the solution for this in case anyone else has this problem. We seemed to have stumbled upon it. Basically, all we ended up doing was in the dbGrid1_Error sub, we set Response = 0. That seems to take care of it.

Thanks to all who posted!



Thanks - Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top