Results 1 to 3 of 3

Thread: Dsn odbc dao vb6

  1. #1

    Thread Starter
    Addicted Member Peekay's Avatar
    Join Date
    Sep 2006
    Witbank, South Africa

    Dsn odbc dao vb6

    I need some advice on opening a MySql database DSN in VB6 with ODBC and DAO.
    The code I use fails, and I do not know why.

    Dim wsODBC As Workspace
    Set wsODBC = DBEngine.CreateWorkspace("ODBCWorkspace", "admin", "", dbUseODBC)
    Workspaces.Append wsODBC
    Dim Conn As Connection
    Set Conn = wsODBC.OpenConnection("Conn1", , , "ODBC;DSN=ibsmsbloem;") - this line gives an error OBDC call failed.
    Dim rs As Recordset
    Set rs = Conn.OpenRecordset("accountterms", dbOpenSnapshot)

    Is there some checklist through which I may work to check that I have done everything right or some examples.


  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    To the moon and then left

    Re: Dsn odbc dao vb6

    Dim Conn As Connection
    Set Conn = wsODBC.OpenConnection("IBSMSbloem")
    see: https://msdn.microsoft.com/de-de/lib.../ff196074.aspx
    If you specify a registered ODBC data source name (DSN) in the connect argument, then the name argument can be any valid string, and will also provide the Name property for the Connection object. If a valid DSN is not included in the connect argument, then name must refer to a valid ODBC DSN, which will also be the Name property.
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    For health reasons i try to avoid reading unformatted Code

  3. #3
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017

    Re: Dsn odbc dao vb6

    Hi Peekay,

    it's been a while since I used DAO, but I'll have go....

    Private Sub Command1_Click()
    Dim ws As Workspace
    Dim cn As Connection
    Dim qd As QueryDef
    Dim rs As Recordset
    Set ws = CreateWorkspace("SQL_Server_ODBC", "", "", dbUseODBC)
    Set cn = ws.OpenConnection("SQL_Server_Conn", dbDriverComplete, False, "ODBC;DSN=TestDaten;UID=USERNAME;")
    Set qd = cn.CreateQueryDef("")
    qd.SQL = "SELECT * FROM YourTable"
    qd.ODBCTimeout = 0
    Set rs = qd.OpenRecordset(dbOpenForwardOnly)
    MsgBox "Name: " & rs!dsName
    Set rs = Nothing
    Set qd = Nothing
    Set cn = Nothing
    Set ws = Nothing
    End Sub
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width