How can I use DAO code to open a database with a password, as well as setting it's recordset?
I don't wanna create a Data Control whenever I wanna do something like that.
Please help.
Thanks.
Woobi
Printable View
How can I use DAO code to open a database with a password, as well as setting it's recordset?
I don't wanna create a Data Control whenever I wanna do something like that.
Please help.
Thanks.
Woobi
Try to use the .openrecordset()
e.g.
Dim QdfSir As QueryDef
Dim RecoMSir As Recordset
'gstrConn is the connect string
With QdfSir
.Connect = gstrConn
.SQL = "Select A.*,B.Sir_Gen_Date From Sir_Items A,Sir B where a.Sir_Code+a.Fin_Suffix=B.Sir_Code+B.Fin_Suffix and B.Sir_Code>='" & TxtFSirNo.Text & "' And B.Sir_Code <= '" & TxtTSirNo.Text & "' And B.Fin_Suffix = '" & TxtFSuffix.Text & "'" & StrSql
Set RecoMSir = .OpenRecordset()
So what do I put as the connect string?
Something like this
gstrConn = "odbc;dsn=" & Trim(gstrDsn) & ";uid=" & Trim(gstrUser) & ";pwd=" & strpw & ";database=" & gstrDb & ";"
Does that mean whenever I try to create a new querydef, I have to reconnect to the database all the time? But what if it's a single user database? That wouldn't cause the program to go haywire?
I thought the database can only be opened once and during the program?
Using DAO to get into an Access database?
Set reference in project to MS DAO 3.6 Object Library.
------------------------------------------------------------------
Dim DB1 as DAO.database
Dim RS1 as DAO.Recordset
Dim ssql as string
Dim pathstringvariable as string
Dim passwordstringvariable as string
pathstringvariable = "C:\MyProjectFolder\SuperDatabase.mdb"
passwordstringvariable="Theshadowknows"
Set DB1 = DAO.opendatabase(Pathstringvariable, false, false, ";pwd=" & passwordstringvariable)
ssql = "SELECT * FROM Table1"
set rs1 = db1.openrecordset(ssql,dbopensnapshot)
------------------------------------------------------------------
Like that.
Hope That helps.
-Jpicasso
P.S. Stay as far away from data controls as possible.
Thanks JPicasso_00, that is exactly what i was looking for. Thanks. =)