How to create a connection in Access database?

G

George

Hi, I am working on an Access form, which is in an Access database.
On the form, I need open a table. But I have no idea how to set the
connection string.
The working environment is Windows XP Home Edition. Access is MS Office
2002.
I tried the following code:

Dim cnn As Connection
Set cnn = New ADODB.Connection
cnn.ConnectionString = "DSN=c:/George/Database/students;UID=sa;PWD=pwd;"
cnn.Open

When open, the error message is:
"Data source name not found and no default driver specified."

what should I do in this circumstance?

Thanks!

George
 
G

Gerald Stanley

If the table is in the same database as the form you are
working on, then set cnn.ActiveConection =
CurrentProject.Connection

Hope This Helps
Gerald Stanley MCSD
 
G

Guest

Gerald,

This is how I do it. If you need to select data from the database.

dim rss as adodb.recordset
dim query as string

query = "select ....... from YOURTABLE Where ......." <--- I type the sql here
set rss = new adodb.recordset
set rss.activeconnection = currentproject.connection
rss.open query

if rss.eof then
msgbox "no records"
else
.......
end if
......

rss.close
set rss = nothing


If you are going to update the table, then I do:

query = "Update YOURTable Set ........ "
docmd.runsql query

I hope this helps

Luisa
 
G

Gerald Stanley

The line below is in error. It should have been
Set cnn = CurrentProject.Connection

Sorry for the confusion
Gerald Stanley MCSD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top