LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Export from Excel to Access ADODB

The following is part of a code in VBA adapted from a code i found in
this forum. It does great when creating the info but i want the code to
work as an update too. In other words it'll find if the record exists
if it does update otherwise create a new one. Any idea?

Dim cn As ADODB.Connection, ct As ADODB.Connection, found As Boolean,
rs As ADODB.Recordset, r As Long, sql As String
' connect to the Access database
If IsEmpty(Range("Información!B3")) Then
Beep
MsgBox "Falta el número de sección"
End
End If
If IsEmpty(Range("Información!B4")) Then
Beep
MsgBox "Falta el número del curso"
End
End If
If IsEmpty(Range("Información!B5")) Then
Beep
MsgBox "Falta el nombre del curso"
End
End If
If IsEmpty(Range("Información!B6")) Then
Beep
MsgBox "Falta la hora de reunión"
End
End If
If IsEmpty(Range("Información!D3")) Then
Beep
MsgBox "Falta el nombre del instructor"
End
End If
If IsEmpty(Range("Información!D4")) Then
Beep
MsgBox "Falta el término"
End
End If
If IsEmpty(Range("Información!D5")) Then
Beep
MsgBox "Faltan los días de reunión"
End
End If
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=E:\UI_Database\Registro Database.mdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "Sección", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 3 ' the start row in the worksheet
rs.Find "section = " & Range("Información!B3").Value
If rs.EOF Then 'No record in table with this ID
rs.AddNew
found = False
End If
rs.Fields("courseno") = Range("Información!B4").Value
rs.Fields("section") = Range("Información!B3").Value
rs.Fields("semester") = Range("Información!D4").Value
rs.Fields("instructor") = Range("Información!D3").Value
rs.Fields("time") = Range("Información!B6").Value
rs.Fields("days") = Range("Información!D5").Value
If found = True Then
rs.Save
Else
rs.Update
End If
' stores/updates the new record
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End


---
Message posted from http://www.ExcelForum.com/

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Export from Access to Excel Teresa NS Excel Discussion (Misc queries) 2 December 2nd 08 06:46 PM
access database (adodb)from excel vba AskExcel Excel Worksheet Functions 0 July 17th 06 02:01 AM
Export to Access from Excel Secret Squirrel Excel Discussion (Misc queries) 0 February 7th 06 11:44 PM
export access to excel. change access & update excel at same time fastcar Excel Discussion (Misc queries) 0 June 24th 05 09:27 PM
Export from Access to Excel Sabina Excel Discussion (Misc queries) 3 February 23rd 05 09:56 PM


All times are GMT +1. The time now is 08:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"