B
batuhan
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 are:
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?
(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 are:
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?