Hi all -
I'm hoping someone can help point me in the right direction. I've spent a lot of time researching this on the internet but nothing I've found is working for exactly what I want to do.
I want to use Access 2003 to do some reporting on a SQL 2005 database located on the network. Access should never modify the SQL database, only pull data from it to work with. I've successfully connected to the database and can copy ALL records from a SQL table into Access. My problem is I can't seem to figure out how to select only certain records to pull into Access. Here's basically the code I'm using so far:
dim rs as ADODB.recordset
dim conn as ADODB.Connection
dim db as Database
dim dbf as Database
dim mycommand as ADODB.Command
set conn = new ADODB.connection
set db=currentdb
set dbf = currentdb
conn.provider="SQLOLEDB.1"
comm.open "connectionstring"
set mycommand = new ADODB.Command
mycommand.activeconnection=conn
mycommand.commandtext = "select field from table"
set rs=new ADODB.recordset
rs.open "table", conn, adOpenDynamic, adLockPessimistic
rs2=dbf.openrecordset("table")
rs.movefirst
do until rs.eof
***copy record to Access, movenext then close everything.
I'm sure this is very sloppy - sorry, trying to learn without any good reference. This works for copying ALL records, but I don't want this. How can I use a SQL select statement to choose only the records that fit my criteria. I understand how to write the select statement, just don't know how to implement it or where the records go after the select statement is used. Any advice is greatly appreciated. Thank you!