Solved

Common Connection routine for VB forms

Posted on 1998-06-18
7
161 Views
Last Modified: 2011-09-20
My application is VB5.0/MSSQLServer based and consists of many forms. I want user to enter his/her login and password one time and then after I would like all the forms, which user navigates thru, should be connected with the supplied login and password (user is not asked to give login and password again).

Can anyone suggest a common subroutine method to do it.
0
Comment
Question by:rolee
  • 4
  • 3
7 Comments
 

Author Comment

by:rolee
ID: 1463688
Edited text of question
0
 
LVL 2

Accepted Solution

by:
marti earned 50 total points
ID: 1463689
You have to have only one global rdoConnection object.
0
 
LVL 2

Expert Comment

by:marti
ID: 1463690
Set the connection only once and use only that connection object to Qry the database. If you need some code please send a comment.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:rolee
ID: 1463691
Just to add:we are using DAO (not RDO).
I would be glad if you could provide some sample code.
Thanks
0
 
LVL 2

Expert Comment

by:marti
ID: 1463692
For DAO it should be the same. Just use one global variable of type Database. Set it when the application starts and use it all over the project.
Regards
0
 

Author Comment

by:rolee
ID: 1463693
Can you give an example. I am sorry as I might be asking too much. Please help.
0
 
LVL 2

Expert Comment

by:marti
ID: 1463694
If SQLServer tables are attached to an existing Access DB you have to use the first example.
Otherwise you may use the next two.

This example uses the OpenDatabase method to open one Microsoft Jet database and two Microsoft Jet-connected ODBC databases.

Sub OpenDatabaseX()

      Dim wrkJet As Workspace
      Dim dbsNorthwind As Database
      Dim dbsPubs As Database
      Dim dbsPubs2 As Database
      Dim dbsLoop As Database
      Dim prpLoop As Property

      ' Create Microsoft Jet Workspace object.
      Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

      ' Open Database object from saved Microsoft Jet database
      ' for exclusive use.
      MsgBox "Opening Northwind..."
      Set dbsNorthwind = wrkJet.OpenDatabase("Northwind.mdb", _

True)

      ' Open read-only Database object based on information in
      ' the connect string.
      MsgBox "Opening pubs..."
      Set dbsPubs = wrkJet.OpenDatabase("Publishers", _
            dbDriverNoPrompt, True, _
            "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

      ' Open read-only Database object by entering only the
      ' missing information in the ODBC Driver Manager dialog
      ' box.
      MsgBox "Opening second copy of pubs..."
      Set dbsPubs2 = wrkJet.OpenDatabase("Publishers", _

dbDriverCompleteRequired, True, _
            "ODBC;DATABASE=pubs;DSN=Publishers;")

      ' Enumerate the Databases collection.
      For Each dbsLoop In wrkJet.Databases
            Debug.Print "Database properties for " & _
                  dbsLoop.Name & ":"

            On Error Resume Next
            ' Enumerate the Properties collection of each Database
            ' object.
            For Each prpLoop In dbsLoop.Properties
                  If prpLoop.Name = "Connection" Then
                        ' Property actually returns a Connection object.

Debug.Print "    Connection[.Name] = " & _
                              dbsLoop.Connection.Name
                  Else
                        Debug.Print "    " & prpLoop.Name & " = " & _
                              prpLoop
                  End If
            Next prpLoop
            On Error GoTo 0

      Next dbsLoop

      dbsNorthwind.Close
      dbsPubs.Close
      dbsPubs2.Close
      wrkJet.Close

End Sub
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now