Solved

Common Connection routine for VB forms

Posted on 1998-06-18
7
162 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

733 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