Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append recordset to table in another access db?

Status
Not open for further replies.

fogal

Technical User
Aug 20, 2001
87
US
I have a recordset that is a set of data gathered from an oracle db. How can I then append this data to a table in another access db?

Please Help?

 
The below code was grabbed from a thread here on Tek-Tips, but I don't remember the author....credit should be given to the creator.....

Let me know if you need some help with the syntax and usage...

' ******* Start Code *************

'Define the API calls
Private Declare Function apiSetForegroundWindow Lib "user32" _
Alias "SetForegroundWindow" _
(ByVal hwnd As Long) _
As Long

Private Declare Function apiShowWindow Lib "user32" _
Alias "ShowWindow" _
(ByVal hwnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_MAXIMIZE = 3
Private Const SW_NORMAL = 1

Public Function Connect2Database(strMDB As String, strTable As String) As Boolean
'strMDB is the full path to the database, strTable is the table name in the database

On Error GoTo ErrorHandler

Dim objAccess As Access.Application
Dim lngRet As Long
Dim db As Database
Dim rs As Recordset

If Len(Dir(strMDB)) > 0 Then
Set objAccess = New Access.Application
With objAccess
lngRet = apiSetForegroundWindow(.hWndAccessApp)
lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
'the first call to ShowWindow doesn't seem to do anything
lngRet = apiShowWindow(.hWndAccessApp, SW_NORMAL)
.OpenCurrentDatabase strMDB
Set db = objAccess.CurrentDb
Set rs = db.OpenRecordset(strTable, dbOpenDynaset)
rs.AddNew
'this section: the first field in the table is index 0 or you can use the names...
' rs.fields(0), rs.Fields(1) or rs.Fields("Name"), rs.Fields("Street")
' add as many a you need prior to the rs.Update
rs.Fields(0) = "Bird"
rs.Update
End With
End If
testme = True

ErrorExit:
objAccess.Quit
Set objAccess = Nothing
Set rs = Nothing
Set db = Nothing
Exit Function

ErrorHandler:
testme = False
Resume ErrorExit

End Function

' ********* End Code *********** Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. (Albert Einstein)

Robert L. Johnson III, MCP, Network+, A+
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top