Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > UpdateDuplicate


Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2001, 06:34 PM
kingesk
Guest
 
Posts: n/a
Question UpdateDuplicate


I am attempting to code some error handeling when a user trys to AddNew and Update with a primary key that already exist.
The error num I got was '-2147467259(800004005)'
I can't seem to trap this error. Any ideas on how to handle this?

Thanks,

Eric



Private Sub mnuUpdate_Click()
'save the added record

On Error GoTo HandleErrors

mRstCurrent("PubId") = txtID
mRstCurrent("Name") = txtName
mRstCurrent("company Name") = txtCoName
mRstCurrent("Address") = txtAddress

mRstCurrent.Update

txtID.SetFocus
lblRecCount = mRstCurrent.RecordCount
lblRecNum = mRstCurrent.AbsolutePosition

Exit Sub

HandleErrors:
Select Case Err:

Case "'-2147467259(80004005)'"
MsgBox "ID already exist, pick id with a unique value", vbOKOnly
mRstCurrent.CancelUpdate
txtID.SetFocus
Exit Sub
Case Else 'all other errors should cancel execution
Err.Raise Err
End Select
Resume

End Sub

Reply With Quote
  #2  
Old 03-08-2001, 10:09 AM
PWNettle PWNettle is offline
Verbose Coder

Retired Moderator
* Guru *
 
Join Date: Dec 1999
Location: Phoenix, Arizona
Posts: 3,011
Default Re: UpdateDuplicate

One way to handle this without using error trapping would be to run a query against the table using the intended key value before the attempted add. If you get a record back from the select you'd know that a record with that key already exists and could respond as you like. If you don't get a record back you know that you can use that key and go ahead and add the new record.

Paul


Reply With Quote
  #3  
Old 03-08-2001, 03:52 PM
klabranche klabranche is offline
Junior Contributor
 
Join Date: May 2000
Location: Arizona
Posts: 288
Default Re: UpdateDuplicate

take out the (800004005) from the case statement and it should work.

http://www.extreme-vb.net/images/icons/smile.gif
Reply With Quote
  #4  
Old 03-09-2001, 07:36 AM
kingesk
Guest
 
Posts: n/a
Default Re: UpdateDuplicate

Thanks,

You were both very helpful.

Eric

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->