ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Addnew (https://www.excelbanter.com/excel-programming/387146-addnew.html)

Brent

Addnew
 
I am uploading data from Excel to Oracle, in which Oracle has a primary key.
I am using a filesearch to get all the files from a folder and upload them to
Oracle, but I need to check the primary key to prevent errors. Already tried
rs.Addnew, the rest of my code, then On error goto to to skip the rs.Update,
but on the next file/iteration of my loop I get an error at rs.Addnew due to
it already being called. Is there a way to "close" rs.Addnew, such as
rs.Delete, or to check if it is "open" (there is a blank row waiting to be
filled) and skip over recalling rs.Addnew? Thank you.

Brent

Jim Jackson

Addnew
 
how about putting the AddNew portion in a Function to be called each time
around?

(Sample from VBA Help.)
Function AddName(rstTemp As Recordset, _
strFirst As String, strLast As String)

' Adds a new record to a Recordset using the data passed
' by the calling procedure. The new record is then made
' the current record.
With rstTemp
.AddNew
!FirstName = strFirst
!LastName = strLast
.Update
.Bookmark = .LastModified
End With

End Function
--
Best wishes,

Jim


"Brent" wrote:

I am uploading data from Excel to Oracle, in which Oracle has a primary key.
I am using a filesearch to get all the files from a folder and upload them to
Oracle, but I need to check the primary key to prevent errors. Already tried
rs.Addnew, the rest of my code, then On error goto to to skip the rs.Update,
but on the next file/iteration of my loop I get an error at rs.Addnew due to
it already being called. Is there a way to "close" rs.Addnew, such as
rs.Delete, or to check if it is "open" (there is a blank row waiting to be
filled) and skip over recalling rs.Addnew? Thank you.

Brent



All times are GMT +1. The time now is 12:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com