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: 22
Default Insert to Access table

I am trying to run the following but I am getting the following error
"object variable or With Block Variable not set", any ideas why??


Sub Insert()

Dim objCommand As ADODB.Command
Dim rsData As ADODB.Recordset
Dim lRecordsAffected As Long
Dim lKey As Long
Dim sConnect As String

' On Error GoTo ErrorHandler

'connection string
sConnect = "Provide=Microsoft.ACE.OLEDB.12.0; Data Source=U:
\intranet\pmdata.mdb; Mode=Share Exclusive"

'command object for statements
Set ojbCommand = New ADODB.Command
objCommand.ActiveConnection = sConnect

'insert statement
objCommand.CommandText = "INSERT INTO table1(Test1, Test2)
VALUES('test456', 'test4567');"

'execute statement
objCommand.Execute 'RecordsAffected:=lRecordsAffected,
Options:=adCmdTxt Or adExecuteNoRecords

If lRecordsAffected < 1 Then Err.Raise Number:=vbObjectError +
1024, Description:="Error executing Insert Statement."

ErrorExit:

'Destroy ADO objects
Set objCommand = Nothing
Set rsData = Nothing

Exit Sub

ErrorHandler:

MsgBox Err.Description, vbCritical
Resume ErrorExit

End Sub

 
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
Write data to Access table with INSERT when table has auto number Hokievandal Excel Programming 1 December 20th 06 01:19 AM
Importing data from Access to Excel, but I need to vary the table from Access Liz L. Excel Programming 3 June 6th 06 02:12 AM
Insert Literal in Access Table using JETSQL Al Excel Programming 0 November 2nd 05 11:53 PM
Is it possible to insert an Access Table object into Excel? Jake Marx[_3_] Excel Programming 6 May 5th 04 04:34 PM
Is it possible to insert an Access Table object into Excel? GJones Excel Programming 0 May 4th 04 02:35 PM


All times are GMT +1. The time now is 01:47 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"