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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DAO Connect with VB2012

Status
Not open for further replies.

MikeCt

Programmer
Nov 6, 2001
44
US
hello
I'm just starting to switch from VB6 to Visual studio 2012 - Visual basic for applications

In the past i've always connected to my access databases with the code listed below
changing the strSQL string to filter my tables. I tried to keep this simply and clear as possible with the example below

(1) Add a reference "Microsoft DAO 3.6 Object Library" to the project

(2) Add a Module with this code
Global gDatabaseDB As Database
Public Sub OpenDB()
Set gDatabaseDB = OpenDatabase(App.Path & "\Database.Mdb")
End Sub

(3) Add a Form with this code

Option Explicit
Dim rsRs As Recordset
Dim strSQL As String

Private Sub Form_Load()
Call OpenDB
strSQL = "SELECT PatientID,FirstName,LastName,PatientActive FROM Patients ORDER BY LastName,FirstName;"
Set rsRs = gDatabaseDB.OpenRecordset(strSQL, dbOpenSnapshot)

If rsRs.EOF Then 'Test for no records
MsgBox ("No Records")
Else
MsgBox ("Records found")
End If
End Sub


Is there a simply way to get the same results in Visual studio 2012?
I need to change the SQL statements often.

Thanks for any help I can get


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top