Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Run Time Error 91! What am I missing?

What am I doing wrong? I get a run time error 91 when I get to
" .CommandText = SqlSet".

please help.


Private Sub UpdateAccess1_Click()

Dim DBFullName As String
Dim Cnct As String
Dim cnn As ADODB.Connection
Dim cmdCommand As ADODB.Command
Dim SqlSet


DBFullName = ThisWorkbook.Path & "\NewAccountDatabase.mdb"

Set cnn = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
cnn.Open ConnectionString:=Cnct

SqlSet = " INSERT INTO AccountMaster ([Account Number], [Account
Name], [Clone Manager])"
SqlSet = SqlSet & " VALUES ( " & Range("Number3").Value & " , " &
Range("Name3").Value & ")" & " , " & Range("Manager3").Value & ");"


With cmdCommand
.CommandText = SqlSet
.CommandType = adCmdText
.Execute
End With


cnn.Close
Set cmdCommand = Nothing
Set cnn = Nothing








End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Run Time Error 91! What am I missing?

Just a guess (since I don't do this often)

Set cmdCommand = New ADODB.Command
Set cmdCommand.ActiveConnection = cnn

before

With cmdCommand
.CommandText = SqlSet


" wrote:

What am I doing wrong? I get a run time error 91 when I get to
" .CommandText = SqlSet".

please help.


Private Sub UpdateAccess1_Click()

Dim DBFullName As String
Dim Cnct As String
Dim cnn As ADODB.Connection
Dim cmdCommand As ADODB.Command
Dim SqlSet


DBFullName = ThisWorkbook.Path & "\NewAccountDatabase.mdb"

Set cnn = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
cnn.Open ConnectionString:=Cnct

SqlSet = " INSERT INTO AccountMaster ([Account Number], [Account
Name], [Clone Manager])"
SqlSet = SqlSet & " VALUES ( " & Range("Number3").Value & " , " &
Range("Name3").Value & ")" & " , " & Range("Manager3").Value & ");"


With cmdCommand
.CommandText = SqlSet
.CommandType = adCmdText
.Execute
End With


cnn.Close
Set cmdCommand = Nothing
Set cnn = Nothing








End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run Time Error 91! What am I missing?

You have not yet set the cmdCommand object to a new or existing
ADODB.Command object. Try including

Set cmdCommand = New ADODB.Command


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





wrote in message
...
What am I doing wrong? I get a run time error 91 when I get to
" .CommandText = SqlSet".

please help.


Private Sub UpdateAccess1_Click()

Dim DBFullName As String
Dim Cnct As String
Dim cnn As ADODB.Connection
Dim cmdCommand As ADODB.Command
Dim SqlSet


DBFullName = ThisWorkbook.Path & "\NewAccountDatabase.mdb"

Set cnn = New ADODB.Connection
Cnct = "Provider=Microsoft.Jet.OLEDB.4.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
cnn.Open ConnectionString:=Cnct

SqlSet = " INSERT INTO AccountMaster ([Account Number], [Account
Name], [Clone Manager])"
SqlSet = SqlSet & " VALUES ( " & Range("Number3").Value & " , " &
Range("Name3").Value & ")" & " , " & Range("Manager3").Value & ");"


With cmdCommand
.CommandText = SqlSet
.CommandType = adCmdText
.Execute
End With


cnn.Close
Set cmdCommand = Nothing
Set cnn = Nothing








End Sub


Reply
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
Inserting missing date/time JWeston Excel Worksheet Functions 0 December 3rd 10 08:53 PM
Missing X error bar options DS Excel Discussion (Misc queries) 1 May 15th 09 04:02 AM
XP VBA Compile error...Missing files Stu78[_3_] Excel Programming 2 October 7th 05 07:35 PM
On Error? Creates 1 missing worksheet then never detects any other missing worksheets Craigm[_35_] Excel Programming 2 August 1st 05 02:39 PM
Missing Word 10 Object Error References Rajan Excel Programming 1 July 23rd 03 02:12 PM


All times are GMT +1. The time now is 07:59 AM.

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

About Us

"It's about Microsoft Excel"