Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Database using code 1

Status
Not open for further replies.

JasGun

Programmer
Feb 28, 2001
12
GB
I have a form as a main menu with several command buttons. When a button is pressed I want the current database to close and to open another database. I'm not sure of the best way to do this, can anyone help?
 
To close the current recodset/database:

Set dbs = Nothing
Set rst = Nothing

To open the 'other' one,

Set dbs = "whatever the database needs to be"
Set rst = "whatever the recordset needs to be"

Or did I miss some complexity?




MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
This method is using the old DAO reference which is not supported by VB 7 as Microsoft are only going to be using ADO references. I would suggest you code your project to use these instead.

Public Function GetRecordSet()

Dim strConnect As String
Dim rst As ADODB.Recordset

strConnect = "DRIVER=Microsoft Access Driver (*.MDB);DBQ=" & App.Path & "\databse name;"
Set connHelpdesk = New ADODB.Connection
Set rst = New ADODB.Recordset
Set rst = ("SELECT * FROM [table name]")
With rst
.ActiveConnection = strConnect
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Source = strsql
.Open
.MoveLast
.MoveFirst

End With
Set GetRecordSet = rst

End Function

It might look a bit daunting at first, but if you make this a module or class, you can pass the SQL directly into it.

Eradic8or
 
Referece to the above. Eliminate the line that says Connhelpdesk = New ADODB.connection as this was for a seperate project.

sorry
Eradic8or
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top