Beginner: Connection String Question

  • Thread starter Thread starter Ed Landau
  • Start date Start date
E

Ed Landau

Hello: I am writing VBA code from within MS Access 2003. I have a table
tblA I'd like to access from VBA code behind a form. Must I just a
connection string if the table I want is right here in the same app? Is
there no way to tell a new recordset to just go execute an SQL string
locally?

The latest books I have are on Access2000.... so I'm not sure if there
something new.

dim strSQL as string
dim rs as ADODB.recordset
strSQL = "SELECT * from tblA;"
'I'd love to do this:
rs.open strSQL ':)




Thanks
-Ed
 
Use CurrentProject.Connection as the connection:

rs.Connection = CurrentProject.Connection
 
It is interesting...

In the follow line, rs has a Connection property, but but I cannot say:
"Set rs = new recordset"
dim rs as recordset

In the following line, rs does NOT have a Connection property but I CAN say
"set rs = new ADODB.recordset.
dim rs as ADODB.recordset

And neither of them have an "Open" method as described in ALL documentation.
Help... I'm confused :)

Thanks
-Ed
 
ADODB.Recordset objects have a connection property.

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Connection = CurrentProject.Connection
rs.Open "SELECT ..."

DAO recordsets don't have an Open method. They use the
CurrentDb.OpenRecordset method to be opened:

Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("SELECT ....")
 
Back
Top