Solved

VB6, ADO, Oracle and Identities

Posted on 2006-11-15
4
537 Views
Last Modified: 2013-12-25
I have a VB6 application that writes a record into an Oracle database.  The record's primary key is the employee id, which is an identity field.  However, after updating the record, I cannot retrieve the key in order to add subsequent child records.

VB6 using ADO 2.8
Connecting via an ODBC DSN that uses sqora32.dll (Oracle in OraHome92).
Transactions enabled.


Here's the code:

With rsEmp
    If bAdding Then
        .AddNew
    End If
    !namefirst = txtFname
    !namelast = txtLname
    lblEmpID.Caption = lCurrentEmp
    !hiredate = txtDateHired
    If IsDate(txtTermDate) Then
        !termdate = txtTermDate
    End If
    If chkSignature = 1 Then
        !issignonfile = "Y"
    Else
        !issignonfile = "N"
    End If
   
    If chkResume = 1 Then
        !iscv = "Y"
    Else
        !iscv = "N"
    End If
    If chkJobDesc = 1 Then
        !ISJOBDESC = "Y"
    Else
        !ISJOBDESC = "N"
    End If
    flexJobTitle.Row = 1
    !jobcode = sJobCode
    !empstatus = cmbStatus
    !emptype = cmbEmpType
    !reason = txtReason
    !Comments = txtComments & ""
    !Name = txtLname & ", " & txtFname
    .Update
    If bAdding Then
' crs working here - not getting the correct empid
        lCurrentEmp = !empid


At this point, lCurrentEmp is set to 0, as the empid field has not updated.  rsEmp was opened as:

    If OpenMode = READWRITE Then
        .CursorType = adOpenDynamic
        .LockType = adLockOptimistic
        .CursorLocation = adUseServer

Do I need to commit the transaction to get the record to update (the BeginTransaction was executed earlier in the code)?  If not, how do I get the value of the employee id after the new record is written?

Thanks in advance!




0
Comment
Question by:Clothahump
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17953773
i think you have to commit the transaction in order to get the record to update.
0
 
LVL 4

Author Comment

by:Clothahump
ID: 17956228
Okay.  I found the solution.  Requerying will force the update.

I change the code as follows:

    .Update
    If bAdding Then
' refresh the table to force the update.  The new record added should now be the first
' in the table since we are ordered by empid desc
        .Requery
        .MoveFirst
        lCurrentEmp = !empid

This does what I want it to.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 18025201
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 88
Access 2013 combo box not working 3 76
MS Access 03, TransferText, decimal places 8 92
can this macro be converted to sub procedure 4 34
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question