ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ADO syntax problem (https://www.excelbanter.com/excel-programming/437974-ado-syntax-problem.html)

אלי

ADO syntax problem
 
Hi!

I am using the following code to query access table. the code works fine. My
problem is how to name the field name ([Cell]) as a string, in order to use
this query as a dynamic query. I tried many things but nothing succeeded.

Thanks for your help!

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Documents and
Settings\Eli\My Documents\ETV_Cells.mdb"
rst.Open "SELECT * FROM CellTable ;", cnn, adOpenStatic
rst.MoveFirst
strCellCode = rst![Cell]

rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing


Eli

JP Ronse

ADO syntax problem
 
Eli,

Declare a variable varCellCode as variant & varCellCode = rst.

Wkr,

JP


"???" wrote in message
...
Hi!

I am using the following code to query access table. the code works fine.
My
problem is how to name the field name ([Cell]) as a string, in order to
use
this query as a dynamic query. I tried many things but nothing succeeded.

Thanks for your help!

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Documents
and
Settings\Eli\My Documents\ETV_Cells.mdb"
rst.Open "SELECT * FROM CellTable ;", cnn, adOpenStatic
rst.MoveFirst
strCellCode = rst![Cell]

rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing


Eli




Tim Williams[_2_]

ADO syntax problem
 
strCellCode = rst.Fields("Cell").Value

Tim



"???" wrote in message
...
Hi!

I am using the following code to query access table. the code works fine.
My
problem is how to name the field name ([Cell]) as a string, in order to
use
this query as a dynamic query. I tried many things but nothing succeeded.

Thanks for your help!

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Documents
and
Settings\Eli\My Documents\ETV_Cells.mdb"
rst.Open "SELECT * FROM CellTable ;", cnn, adOpenStatic
rst.MoveFirst
strCellCode = rst![Cell]

rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing


Eli





All times are GMT +1. The time now is 11:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com