Solved

trivial thing

Posted on 1998-12-11
3
185 Views
Last Modified: 2010-05-03
how to use odbc api in the visual basic ?
0
Comment
Question by:rayau
  • 2
3 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 1449643
Hi Rayau,

This coming straight from the helpfile

Sub OpenConnectionX()

      Dim wrkODBC As Workspace
      Dim conPubs As Connection
      Dim conPubs2 As Connection
      Dim conPubs3 As Connection
      Dim conLoop As Connection

      ' Create ODBCDirect Workspace object.
      Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
            "admin", "", dbUseODBC)

      ' Open Connection object using supplied information in
      ' the connect string. If this information were
      ' insufficient, you could trap for an error rather than
      ' go to an ODBC Driver Manager dialog box.

MsgBox "Opening Connection1..."
      Set conPubs = wrkODBC.OpenConnection("Connection1", _
            dbDriverNoPrompt, , _
            "ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

      ' Open read-only Connection object based on information
      ' you enter in the ODBC Driver Manager dialog box.
      MsgBox "Opening Connection2..."
      Set conPubs2 = wrkODBC.OpenConnection("Connection2", _
            dbDriverPrompt, True, "ODBC;DSN=Publishers;")

      ' Open read-only Connection object by entering only the

' missing information in the ODBC Driver Manager dialog
      ' box.
      MsgBox "Opening Connection3..."
      Set conPubs3 = wrkODBC.OpenConnection("Connection3", _
            dbDriverCompleteRequired, True, _
            "ODBC;DATABASE=pubs;DSN=Publishers;")

      ' Enumerate the Connections collection.
      For Each conLoop In wrkODBC.Connections
            Debug.Print "Connection properties for " & _
                  conLoop.Name & ":"

            With conLoop
                  ' Print property values by explicitly calling each

' Property object; the Connection object does not
                  ' support a Properties collection.
                  Debug.Print "    Connect = " & .Connect
                  ' Property actually returns a Database object.
                  Debug.Print "    Database[.Name] = " & _
                        .Database.Name
                  Debug.Print "    Name = " & .Name
                  Debug.Print "    QueryTimeout = " & .QueryTimeout
                  Debug.Print "    RecordsAffected = " & _
                        .RecordsAffected
                  Debug.Print "    StillExecuting = " & _

StillExecuting
                  Debug.Print "    Transactions = " & .Transactions
                  Debug.Print "    Updatable = " & .Updatable
            End With

      Next conLoop

      conPubs.Close
      conPubs2.Close
      conPubs3.Close
      wrkODBC.Close

End Sub


It creates a directworkspace and then opens an connection to a specified database.

Hope this helps
br(UINT)je.

0
 
LVL 1

Accepted Solution

by:
bear454 earned 50 total points
ID: 1449644
Sub OpenConnectionX()

Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim conPubs2 As Connection
Dim conPubs3 As Connection
Dim conLoop As Connection

' Create ODBCDirect Workspace object.
Set wrkODBC = CreateWorkspace("NewODBCWorkspace", _
"admin", "", dbUseODBC)

' Open Connection object using supplied information in
' the connect string. If this information were
' insufficient, you could trap for an error rather than
' go to an ODBC Driver Manager dialog box.

MsgBox "Opening Connection1..."
Set conPubs = wrkODBC.OpenConnection("Connection1", _
dbDriverNoPrompt, , _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")

' Open read-only Connection object based on information
' you enter in the ODBC Driver Manager dialog box.
MsgBox "Opening Connection2..."
Set conPubs2 = wrkODBC.OpenConnection("Connection2", _
dbDriverPrompt, True, "ODBC;DSN=Publishers;")

' Open read-only Connection object by entering only the

' missing information in the ODBC Driver Manager dialog
' box.
MsgBox "Opening Connection3..."
Set conPubs3 = wrkODBC.OpenConnection("Connection3", _
dbDriverCompleteRequired, True, _
"ODBC;DATABASE=pubs;DSN=Publishers;")

' Enumerate the Connections collection.
For Each conLoop In wrkODBC.Connections
Debug.Print "Connection properties for " & _
conLoop.Name & ":"

With conLoop
' Print property values by explicitly calling each

' Property object; the Connection object does not
' support a Properties collection.
Debug.Print "    Connect = " & .Connect
' Property actually returns a Database object.
Debug.Print "    Database[.Name] = " & _
Database.Name
Debug.Print "    Name = " & .Name
Debug.Print "    QueryTimeout = " & .QueryTimeout
Debug.Print "    RecordsAffected = " & _
RecordsAffected
Debug.Print "    StillExecuting = " & _

StillExecuting
Debug.Print "    Transactions = " & .Transactions
Debug.Print "    Updatable = " & .Updatable
End With

Next conLoop

conPubs.Close
conPubs2.Close
conPubs3.Close
wrkODBC.Close

End Sub


It creates a directworkspace and then opens an connection to a specified database.

0
 
LVL 44

Expert Comment

by:bruintje
ID: 1449645
Hahahahhaha,

Well, well I'm a real Bear too, so I have to ask if this is a joke or something thought we were after the Bulls :O).

Posting my comment as an answer, hmmmm.

Just to revive the Q.

Sleepzzzzzzzzzzzz.
Bruintje.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 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

16 Experts available now in Live!

Get 1:1 Help Now