help with database connection - urgent

J

joao

Hi

i got this code from a web site and its working, i just need to inser
the password of my database and i really don't know where it shoul
go.

Anyone could help?


Written : 23-May-2003 by Andy Wiggins - Byg Software Ltd

Function DbSource()
DbSource = ThisWorkbook.Path & "/bdalunosindex.mdb"
End Function

Function DbConnection()
DbConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=
& DbSource & ";"
End Function

Sub SelectAndReturnRecordsADO()
Dim cnn As ADODB.Connection
Dim rstRecordset As ADODB.Recordset
Dim cmdCommand As ADODB.Command
Dim numberOfRows
Dim vtSql
Dim c As Field

'' Open the connection.
Set cnn = New ADODB.Connection
cnn.Open DbConnection

'' Set the command text.


Set cmdCommand = New ADODB.Command
Set cmdCommand.ActiveConnection = cnn



vtSql = " SELECT * FROM Pagamento ORDER BY Pagamento.c_Contrato"

With cmdCommand
.CommandText = vtSql
.CommandType = adCmdText
.Execute
End With

'' Open the recordset.
Set rstRecordset = New ADODB.Recordset
Set rstRecordset.ActiveConnection = cnn
rstRecordset.Open cmdCommand
rstRecordset.MoveFirs
 
D

Dick Kusleika

joao

Use Data - Get External Data to create a new QueryTable in a new workbook
using the same database. Then, in the immediate window, type

?Sheet1.QueryTables(1).Connection

to get the propert connection string for that query. Dump the ODBC part at
the start and that's what you should use for your DbConnection variable.
 
J

joao

Hi,

TYhanks for your help, but it isnt working for me. I tried the link an
the two options but it now returns another error message (before wa
invalid password) now it says something about my workgroup and someon
that have opened the database in exclusive mode.

any other idea
 
D

Dick Kusleika

joao

What connection string did you get with the query table? What connection
string are you using in your code?
 
S

Sam

Hi,

When you open the connection do somethin'like this:


cnn.Open "DSN=mydatabase", just to make it easy... add a the
"mydatabase" to the ODBC manager, there you can provide the username
and password...
 

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