VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Access Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-01-2012, 10:00 AM   #1
waqas

 
Joined: Feb 2012
Posts: 15
Kb Entries: 0
Articles: 0
Cool Overwrite on existing Record

Dear Experts,

i am uploading data from excel using below code.

now i want to do overwrite on existing data in access table.

what should i do? how can i get.

Public Sub DoExcelImport()
' Excel object variables
Dim appExcel As Excel.Application
Dim wbk As Excel.Workbook
Dim wks As Excel.Worksheet
'*********Leave ReocardSet
Dim LeaveRec As Recordset, dbs As Database
'*******************
Dim rs2 As New ADODB.Recordset, IDFind As String
Dim cnn2 As New ADODB.Connection
Dim cmd2 As New ADODB.Command, SourceRange As String

SourceFile = CurrentProject.Path & "\Leave1.xlsx"


Set rsCon = CreateObject("ADODB.Connection")


With cnn2
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & SourceFile & ";Extended Properties=""" & "Excel 12.0 Xml;HDR=YES;IMEX=1;" & """"
.Open
End With
Set cmd2.ActiveConnection = cnn2
cmd2.CommandType = adCmdText
cmd2.CommandText = "SELECT * FROM [Sheet1$]"

rs2.CursorType = adOpenStatic

rs2.Open cmd2


Set dbs = DBEngine(0)(0)
Set LeaveRec = dbs.OpenRecordset("Leave", dbOpenTable)

For i = 1 To rs2.RecordCount
With LeaveRec
.AddNew
.Fields(0) = rs2.Fields(0)
.Fields(1) = rs2.Fields(1)
.Fields(2) = rs2.Fields(2)
.Fields(3) = rs2.Fields(3)
.Update

End With
rs2.MoveNext
Next


Set wks = Nothing
Set appExcel = Nothing
rs2.Close
cnn2.Close
doExcelAutomationExit:
Exit Sub
doExcelAutomation:
MsgBox Err.Description, vbOKOnly, Err.Source & ":" & Err.Number
Resume doExcelAutomationExit
End Sub

Local Time: 02:53 AM
Local Date: 05-26-2013
Location:

 
Reply With Quote Top
Reply



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 02:53 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express