Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default calling data from access

i have the following code and gives the error "Run-time error: '-2147217900
(80040e14)': String error in 'ProductId ='

Sub GetData()

Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary

sConnect = " Provider = Microsoft.Jet.OLEDB.4.0; " & " Data Source= " &
"C:\Temp\product.mdb"
sSQL = "SELECT Price FROM Products WHERE ProductId = " &
Range("A10").Value
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not oRS.EOF Then
Sheet1.Range("C2").CopyFromRecordset oRS
Else
MsgBox (No data)
End If

oRS.Close
Set oRS = Nothing

End Sub

My db name = product.mdb
table name in my db = products
What i want to do is to call the value in 'price' column from my
'product.mdb' database to an excel sheet. My db columns a

column1 = ProductId
column2 = ProductName
column3 = Price

My excel columns are named as

A1 = ProductId
B1 = ProductName
C1 = Price

For example, when i write ProductId to my A2 cell, it will call that
product's price from the db and put the value to C2 cell.

How can i correct the error?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default calling data from access

Going by the error ("String error in 'ProductId ="), I would assume you are
passing a string when it should be number.
Or if it should be a string, you are not enclosing it in quotes ;
sSQL = "SELECT Price FROM Products WHERE ProductId = " & Chr(34) &
Range("A10").Value & Chr(34)
Depends how your Products.ProductID column is defined.

NickHK

"batuhan" wrote in message
...
i have the following code and gives the error "Run-time error:

'-2147217900
(80040e14)': String error in 'ProductId ='

Sub GetData()

Const adOpenForwardOnly As Long = 0
Const adLockReadOnly As Long = 1
Const adCmdText As Long = 1
Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim ary

sConnect = " Provider = Microsoft.Jet.OLEDB.4.0; " & " Data Source= "

&
"C:\Temp\product.mdb"
sSQL = "SELECT Price FROM Products WHERE ProductId = " &
Range("A10").Value
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not oRS.EOF Then
Sheet1.Range("C2").CopyFromRecordset oRS
Else
MsgBox (No data)
End If

oRS.Close
Set oRS = Nothing

End Sub

My db name = product.mdb
table name in my db = products
What i want to do is to call the value in 'price' column from my
'product.mdb' database to an excel sheet. My db columns a

column1 = ProductId
column2 = ProductName
column3 = Price

My excel columns are named as

A1 = ProductId
B1 = ProductName
C1 = Price

For example, when i write ProductId to my A2 cell, it will call that
product's price from the db and put the value to C2 cell.

How can i correct the error?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default calling data from access

All columns in products database are default, i've made no changes to their
definitions (number or string). The ID's consist of both numbers and
characters (like 1a.23 or 2c.44.65). The code you gave me made a 'type
mismatch' error. Any other ideas? (Maybe a different solution from my code).

If it will be easier, i may import my db to another sheet and call data from
excel to excel, but i'll need the code to do that

"NickHK" wrote:

Going by the error ("String error in 'ProductId ="), I would assume you are
passing a string when it should be number.
Or if it should be a string, you are not enclosing it in quotes ;
sSQL = "SELECT Price FROM Products WHERE ProductId = " & Chr(34) &
Range("A10").Value & Chr(34)
Depends how your Products.ProductID column is defined.

NickHK

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default calling data from access

Do Debug.Print sSQL
What do you get ?

NickHK

"batuhan" ...
All columns in products database are default, i've made no changes to
their
definitions (number or string). The ID's consist of both numbers and
characters (like 1a.23 or 2c.44.65). The code you gave me made a 'type
mismatch' error. Any other ideas? (Maybe a different solution from my
code).

If it will be easier, i may import my db to another sheet and call data
from
excel to excel, but i'll need the code to do that

"NickHK" wrote:

Going by the error ("String error in 'ProductId ="), I would assume you
are
passing a string when it should be number.
Or if it should be a string, you are not enclosing it in quotes ;
sSQL = "SELECT Price FROM Products WHERE ProductId = " & Chr(34) &
Range("A10").Value & Chr(34)
Depends how your Products.ProductID column is defined.

NickHK



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
calling access data from excel batuhan Excel Discussion (Misc queries) 1 August 18th 06 10:17 AM
Calling a specific version of Access. Derek Anderson Excel Programming 2 June 17th 05 09:00 PM
calling a stored access query from excel vba Travis Excel Programming 1 April 25th 05 09:11 PM
calling an MS Access query from within VBA for Excel Shane Ambry Excel Programming 0 August 18th 04 08:38 AM
Calling Access Program from Excel John Baker Excel Programming 1 April 24th 04 01:20 PM


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

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"