473,695 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update an Oracle table, get 3167 error on faked Autonumber ID field

We're starting to use Oracle for the back-end instead of a separate
Access .mdb file for the data and everything as gone surprisingly well
so far. We are learning Oracle as we go; Yikes! But we have very
patient DBA's at the main office to answer newbie questions.

Using Access 2002 with linked ODBC tables to Oracle 9 (9i? not sure),
ODBC driver is SQORA32.DLL, verson 9.02.00.00.

My "Error 3167: Record is deleted" comes when I use .AddNew, .Update,
..Bookmark, then try to grab the "faked" Autonumber ID of the record
just entered, like I've done in Access many times before (code is
below).

For most things I have the users enter records into forms and
everything works just as it did with the tables in an Access back-end.
But for this table (long story) I have them click a button to get the
new record started, then I want to make that record current so they can
finish putting values in the rest of the fields.

This is how I've faked an Autonumber ID in Oracle:
1. set up the ID as primary key
2. set up a Sequence
3. set up a Trigger:
CREATE OR REPLACE TRIGGER MFD.BIFER_SIGLE GFEATURE_ID_PK
BEFORE INSERT
ON MFD.SIG_LEG_FEA TURE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
BEGIN
SELECT siglegfeature_s eq.NEXTVAL INTO :NEW.FEATURE_ID FROM dual;
END bifer_siglegfea ture_id_pk;

This seems to make FEATURE_ID behave just like an Access Autonumber
field except in this instance.
' /\/\/\/\/\/\/\/ START CODE
Private Sub btnAddFeature_C lick()
On Error GoTo Err_btnAddFeatu re_Click
Dim rst As Recordset
Dim rstClone As Recordset
Dim intID As Long

If IsNull(txtLegNb r) Then
MsgBox "Please select a Leg/Approach", , "NO LEG SELECTED"
Else

Set rst = CurrentDb.OpenR ecordset("SIG_L EG_FEATURE")

With rst
.AddNew
.Fields![LEG_NUM] = txtLegNbr
.Fields![SYSTEM_ID_NO] = curSysID
.Update
.Bookmark = .LastModified
'** This next line throws the error 3167 **
intID = rst.Fields![FEATURE_ID]
End With

'** I'm kind of rusty on using bookmarks, too ...
Forms![frmMainSignals]![frmFeature].Form.Requery
Set rstClone = Me.RecordsetClo ne
rstClone.FindFi rst "[FEATURE_ID] = " & intID
If rstClone.NoMatc h Then
MsgBox "Not found"
Else
' Display the found record in the form.
Forms![frmMainSignals]![frmFeature].Form.Bookmark =
rstClone.Bookma rk
End If

End If

Exit_btnAddFeat ure_Click:

On Error Resume Next
rst.Close
Set rst = Nothing
rstClone.Close
Set rstClone = Nothing

Exit Sub

Err_btnAddFeatu re_Click:
MsgBox "Error " & Err.Number & ": " & Err.DESCRIPTION ,
vbInformation, "Add Feature ERROR"
Resume Exit_btnAddFeat ure_Click

End Sub
' /\/\/\/\/\/\/\/ END CODE

I've set a breakpoint at the top and checked the data in Oracle using
TOAD and the new record is really there and FEATURE_ID is filled in
with the next number in sequence as soon as the .Update line is run.
The .Bookmark line also runs fine. The Recordset just doesn't seem to
know that the value of FEATURE_ID is now filled in. So it calls it
deleted??

Should I be making a dbUseODBC workspace? I haven't had to deal with
workspaces before, when using Access back-ends.

Any advice on this would be greatly appreciated. THANKS!
Denise

Nov 13 '05 #1
4 3331
My References are:
1. VBA
2. Access 10 Object Library
3. DAO 3.6 Object Library
4. Office 10 Object Library (I don't usually include this but I'm doing
something elsewhere that needed it. Maybe Application.Fil eSearch?)

Nov 13 '05 #2
Hello.

Why do you use before triger for autoincrement ID primary key ?
I don't know how it works with Oracle, but in PostgreSQL (should be similar
to Oracle) you can set field datatype to BIGSERIAL. The server then creates
the sequence itself, so there is no need for any trigger. I suppose that
there is something similar in Oracle...
I avoid triggers. I use them only for audit trail...

Bye.
<dh*******@yaho o.com> je napisao u poruci interesnoj
grupi:11******* *************** @g44g2000cwa.go oglegroups.com. ..
We're starting to use Oracle for the back-end instead of a separate
Access .mdb file for the data and everything as gone surprisingly well
so far. We are learning Oracle as we go; Yikes! But we have very
patient DBA's at the main office to answer newbie questions.

Using Access 2002 with linked ODBC tables to Oracle 9 (9i? not sure),
ODBC driver is SQORA32.DLL, verson 9.02.00.00.

My "Error 3167: Record is deleted" comes when I use .AddNew, .Update,
.Bookmark, then try to grab the "faked" Autonumber ID of the record
just entered, like I've done in Access many times before (code is
below).

For most things I have the users enter records into forms and
everything works just as it did with the tables in an Access back-end.
But for this table (long story) I have them click a button to get the
new record started, then I want to make that record current so they can
finish putting values in the rest of the fields.

This is how I've faked an Autonumber ID in Oracle:
1. set up the ID as primary key
2. set up a Sequence
3. set up a Trigger:
CREATE OR REPLACE TRIGGER MFD.BIFER_SIGLE GFEATURE_ID_PK
BEFORE INSERT
ON MFD.SIG_LEG_FEA TURE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
BEGIN
SELECT siglegfeature_s eq.NEXTVAL INTO :NEW.FEATURE_ID FROM dual;
END bifer_siglegfea ture_id_pk;

This seems to make FEATURE_ID behave just like an Access Autonumber
field except in this instance.
' /\/\/\/\/\/\/\/ START CODE
Private Sub btnAddFeature_C lick()
On Error GoTo Err_btnAddFeatu re_Click
Dim rst As Recordset
Dim rstClone As Recordset
Dim intID As Long

If IsNull(txtLegNb r) Then
MsgBox "Please select a Leg/Approach", , "NO LEG SELECTED"
Else

Set rst = CurrentDb.OpenR ecordset("SIG_L EG_FEATURE")

With rst
.AddNew
.Fields![LEG_NUM] = txtLegNbr
.Fields![SYSTEM_ID_NO] = curSysID
.Update
.Bookmark = .LastModified
'** This next line throws the error 3167 **
intID = rst.Fields![FEATURE_ID]
End With

'** I'm kind of rusty on using bookmarks, too ...
Forms![frmMainSignals]![frmFeature].Form.Requery
Set rstClone = Me.RecordsetClo ne
rstClone.FindFi rst "[FEATURE_ID] = " & intID
If rstClone.NoMatc h Then
MsgBox "Not found"
Else
' Display the found record in the form.
Forms![frmMainSignals]![frmFeature].Form.Bookmark =
rstClone.Bookma rk
End If

End If

Exit_btnAddFeat ure_Click:

On Error Resume Next
rst.Close
Set rst = Nothing
rstClone.Close
Set rstClone = Nothing

Exit Sub

Err_btnAddFeatu re_Click:
MsgBox "Error " & Err.Number & ": " & Err.DESCRIPTION ,
vbInformation, "Add Feature ERROR"
Resume Exit_btnAddFeat ure_Click

End Sub
' /\/\/\/\/\/\/\/ END CODE

I've set a breakpoint at the top and checked the data in Oracle using
TOAD and the new record is really there and FEATURE_ID is filled in
with the next number in sequence as soon as the .Update line is run.
The .Bookmark line also runs fine. The Recordset just doesn't seem to
know that the value of FEATURE_ID is now filled in. So it calls it
deleted??

Should I be making a dbUseODBC workspace? I haven't had to deal with
workspaces before, when using Access back-ends.

Any advice on this would be greatly appreciated. THANKS!
Denise

Nov 13 '05 #3
dh*******@yahoo .com wrote:
We're starting to use Oracle for the back-end instead of a separate
I don't use Oracle as linked tables in Access, I tend to use pass
through queries and will also be using ADO eventually. So I don't
really have anything Oracle related to suggest.
CREATE OR REPLACE TRIGGER MFD.BIFER_SIGLE GFEATURE_ID_PK
BEFORE INSERT
ON MFD.SIG_LEG_FEA TURE
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
BEGIN
SELECT siglegfeature_s eq.NEXTVAL INTO :NEW.FEATURE_ID FROM dual;
END bifer_siglegfea ture_id_pk;
I don't use the DECLARE line nor do I qualify the end statement with the
name of the trigger as you've done here, but it's working so I guess
it's OK.
With rst
.AddNew
.Fields![LEG_NUM] = txtLegNbr
.Fields![SYSTEM_ID_NO] = curSysID
.Update
.Bookmark = .LastModified
'** This next line throws the error 3167 **
intID = rst.Fields![FEATURE_ID]
End With
Have you tried removing the rst? It seems to me the line causing the
error should be:

intID = .Fields![FEATURE_ID]
Should I be making a dbUseODBC workspace? I haven't had to deal with
workspaces before, when using Access back-ends.


I've never bothered.

Not much help, I know, but I take interest in Oracle related questions
and I saw this one had not been answered.

On Zlatko's post, you do need a trigger to incorporate a sequence with a
table.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Nov 13 '05 #4
Thanks Zlatko and Tim for responses.

I've worked around trying to find out what the Feature_ID is on the
newly inserted record. Instead I show them a small form that makes them
define the last piece I need to make a unique new record. Then I insert
the record and show them the main form which they can tweak at this
point. I don't think removing the superfluous rst made a difference.

The working code is below.
Thanks again!
Denise

Private Sub btnAddFeature_C lick()
On Error GoTo Err_btnAddFeatu re_Click
Dim rst As Recordset
Dim rstClone As Recordset
Dim intID As Long
Dim varNewRec As Variant

intFeatureID = 0 ' set as Public in MainMod, stays 0 if user
cancels frmNewFeature

If IsNull(txtLegNb r) Then
MsgBox "Please select a Leg/Approach", , "NO LEG SELECTED"
Else
DoCmd.OpenForm "frmNewFeature" , , , , , acDialog

If intFeatureID <> 0 Then

Set rst = CurrentDb.OpenR ecordset("SIG_L EG_FEATURE",
dbOpenDynaset)

With rst
.AddNew
.Fields![SYSTEM_ID_NO] = curSysID
.Fields![LEG_NUM] = txtLegNbr
.Fields![FEATURE_TYPE_ID] = intFeatureID
.Fields![INSTALLED_DT] = Date
.Update
End With

Me.Requery
Me.Refresh
Set rstClone = Me!frmFeature.F orm.RecordsetCl one
rstClone.FindFi rst "[SYSTEM_ID_NO] = " & curSysID & " and
[LEG_NUM] = " & txtLegNbr & " and [FEATURE_TYPE_ID] = " & intFeatureID
If rstClone.NoMatc h Then
MsgBox "Not found"
Else
'Display the found record in the form.
Me!frmFeature.F orm.Bookmark = rstClone.Bookma rk
Me!frmFeature.F orm.Controls!IN STALLED_DT.SetF ocus
End If

End If ' end of if intFeatureID <> 0

End If ' end of if isNull txtLegNbr
Exit_btnAddFeat ure_Click:

On Error Resume Next
rst.Close
Set rst = Nothing
rstClone.Close
Set rstClone = Nothing

Exit Sub

Err_btnAddFeatu re_Click:
If Err.Number = 3146 Then
MsgBox "That feature already entered for this approach. No
action taken", vbInformation, "Feature Exists"
Else
MsgBox "Error " & Err.Number & ": " & Err.DESCRIPTION ,
vbInformation, "Add Feature ERROR"
End If
Resume Exit_btnAddFeat ure_Click

End Sub

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2775
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
4
10230
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline View Query: Select Sq from ( Select substr(to_date(End_Date,"DD-MON-YYYY"),4), End_Date, Rank() Over (Partition by substr(to_date(End_Date,"DD-MON-YYYY"),4) Order by End_Date) As Sq
3
6309
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field new field table 2 has: key field (autonumber)
33
4284
by: Lee C. | last post by:
I'm finding this to be extremely difficult to set up. I understand that Access won't manage the primary key and the cascade updates for a table. Fine. I tried changing the PK type to number and setting default value to a UDF that manages the auto-numbering. Access won't take a UDF as a default value. Okay, I'll use SQL WITHOUT any aggregate functions, for the default value. Access won't do that either. Okay, I create a second...
0
1911
by: EKL | last post by:
Hi, I'm making a sort of Customer and Orders database in MS Access 2003. My problem is that I wish to update the table "tblTransaction" based on changes made in the table "tblOrderDetails". There is no direct relationship between these two tables. The "tblProducts" has a one-to-many relationship to " tblOrderDetails" and "tblTransaction". I use the "tblTransaction" to count number of items in stock for each product. I therefore wish...
5
3537
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I do the update the changed parentid in the child table fails to change. No error is given its just that the change is not written to the Database. When I step through the records for the child table the one I would expect to be changed has a row...
3
3383
by: Darin | last post by:
This is something that on the surface seems like it should be simple, but I can't think of a way to do this. I have a table that is a list of "jobs", which users create and use. It has a single autonumber key field. Within a job, there can be multiple orders. Logically, there'd be an orders table that is a child of the job table. This orders table has a long integer field that matches it to the master job autonumber field. ...
2
11152
by: travhale | last post by:
in a new project using .net 2005, c#. getting err message "Update requires a valid UpdateCommand when passed DataRow collection with modified rows." source RDBMS is oracle 8i. I add a new dataset to the project and drag a datatable from server explorer onto the dataset design surface. In the configuration wizard, under advanced options the "refresh data table" is disabled ie I am not able to check it (note if the source db is sql...
16
3499
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
8565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8977
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2997
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.