ADO - password

G

gatarossi

Dear all,

I'm trying to obtain some datas in excel from access, but I must to
put a simple password in my access file. Then the code below doesn't
work because the access's password. How can I solve this problem?


Sub gross_margin()
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
Dim xinput As Variant

xinput = InputBox("Digite o N.º do Pi:", "Consulta de Pi")

sql = "select alsis, pi, line, item, descricao_item, ano_mes_base,
quantidade, net_value_R$, cost, gm_R$, gm_MSDS_R$ from gross_margin "
sql = sql & "WHERE pi ='" & xinput & "' "

filenm = "J:\Custos\Fechamento Mensal\custo_pedidos.mdb"

Call GetCn(adoconn, adors, sql, filenm, "", "")

adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
Set xinput = Nothing
End Sub

Public Sub GetCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As
ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)


Set dbcon = New ADODB.Connection
dbcon.Open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile &
";", _
usernm, pword

Set dbrs = New ADODB.Recordset

dbrs.Open sqlstr, dbcon


End Sub

For example my password is xxx001.

Thanks!

André.
 
G

George Nicholson

have you tried:
Call GetCn(adoconn, adors, sql, filenm, "", "xxx001")
?

What happens when you do? What error message do you get?

You might also try:
Call GetCn(adoconn, adors, sql, filenm & ";Pwd='xxx001'", "", "")

HTH,


Dear all,

I'm trying to obtain some datas in excel from access, but I must to
put a simple password in my access file. Then the code below doesn't
work because the access's password. How can I solve this problem?


Sub gross_margin()
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
Dim xinput As Variant

xinput = InputBox("Digite o N.º do Pi:", "Consulta de Pi")

sql = "select alsis, pi, line, item, descricao_item, ano_mes_base,
quantidade, net_value_R$, cost, gm_R$, gm_MSDS_R$ from gross_margin "
sql = sql & "WHERE pi ='" & xinput & "' "

filenm = "J:\Custos\Fechamento Mensal\custo_pedidos.mdb"

Call GetCn(adoconn, adors, sql, filenm, "", "")

adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
Set xinput = Nothing
End Sub

Public Sub GetCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As
ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)


Set dbcon = New ADODB.Connection
dbcon.Open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile &
";", _
usernm, pword

Set dbrs = New ADODB.Recordset

dbrs.Open sqlstr, dbcon


End Sub

For example my password is xxx001.

Thanks!

André.
 
D

Douglas J. Steele

dbcon.Open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
dbfile &";Jet OLEDB:Database Password=xxx001", _
usernm, pword


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dear all,

I'm trying to obtain some datas in excel from access, but I must to
put a simple password in my access file. Then the code below doesn't
work because the access's password. How can I solve this problem?


Sub gross_margin()
Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
Dim xinput As Variant

xinput = InputBox("Digite o N.º do Pi:", "Consulta de Pi")

sql = "select alsis, pi, line, item, descricao_item, ano_mes_base,
quantidade, net_value_R$, cost, gm_R$, gm_MSDS_R$ from gross_margin "
sql = sql & "WHERE pi ='" & xinput & "' "

filenm = "J:\Custos\Fechamento Mensal\custo_pedidos.mdb"

Call GetCn(adoconn, adors, sql, filenm, "", "")

adors.Close
adoconn.Close
Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing
Set xinput = Nothing
End Sub

Public Sub GetCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As
ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)


Set dbcon = New ADODB.Connection
dbcon.Open "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile &
";", _
usernm, pword

Set dbrs = New ADODB.Recordset

dbrs.Open sqlstr, dbcon


End Sub

For example my password is xxx001.

Thanks!

André.
 

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