early/late binding DAO


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: early/late binding DAO

  1. #1
    Robert R. Guest

    early/late binding DAO


    This is a shot in the dark but -

    I have some code where I need to use late binding to open a DAO database
    object using a system DSN. The problem I am having is that on the machine
    I need to run this code, late binding does not work. So for testing, I created
    a small VB test app with two routines - one that uses early binding and one
    that uses late binding. Both routines work fine on my machine, but only
    the early binding routine works on the target machine.

    I have to use late binding because ultimately, this code will be used in
    a Lotus Notes routine and there is no way to use early binding in Notes.


    Here are my test routines. The late binding routine is crashing on the CreateObject
    line.


    Private Sub cmdTestEarly_Click()
    Dim dbE As DAO.DBEngine
    Dim ws As DAO.Workspace
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strConnect As String

    Set dbE = New DAO.DBEngine

    'On the target machine this message says "Version: 3.51"
    MsgBox "Version: " & DAO.DBEngine.Properties("Version")

    Set ws = dbE.CreateWorkspace("", "admin", "", dbUseJet)

    strConnect = "ODBC;;DSN=testdsn;"
    Set db = ws.OpenDatabase("", False, True, strConnect)

    Set rst = db.OpenRecordset( _
    "select count(*) as numrecs from testtable", _
    dbOpenSnapshot, dbReadOnly)

    MsgBox "Records Found: " & Trim(Str(rst("numrecs")))

    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
    ws.Close
    Set ws = Nothing
    Set dbE = Nothing
    End Sub


    Private Sub cmdTestLate_Click()
    Dim dbE As Object
    Dim ws As Object
    Dim db As Object
    Dim rst As Object
    Dim strConnect As String

    Set dbE = CreateObject("DAO.DBEngine.35") '????Crashes here????

    Set ws = dbE.CreateWorkspace("", "admin", "", dbUseJet)

    strConnect = "ODBC;;DSN=testdsn;"

    Set db = ws.OpenDatabase("", False, True, strConnect)

    Set rst = db.OpenRecordset( _
    "select count(*) as numrecs from testtable", _
    dbOpenSnapshot, dbReadOnly)

    MsgBox "Records Found: " & Trim(Str(rst("numrecs")))

    rst.Close
    Set rst = Nothing
    db.Close
    Set db = Nothing
    ws.Close
    Set ws = Nothing
    Set dbE = Nothing

    End Sub


    I have searched MDSN and found articles on runtime licensing which said to
    add registry keys and so on. Nothing has worked yet. Does anyone have any
    idea what would cause the late binding not to work?

    My machine is NT 4, VB6 SP3 and the target machine is Win95 with DCOM95 and
    MDAC. Both machines have MDAC 2.1 installed.


    Thanks,
    Robert.



  2. #2
    Arthur Wood Guest

    Re: early/late binding DAO


    Robert,
    try this change...

    Set dbE = CreateObject("DAO.DBEngine")

    that is, do not specify the version of the DEEngine that you want to use.

    That way you will get whatever version is actually installed on the target
    machine.

    Arthur Wood


    "Robert R." <rrichie@hotmail.com> wrote:
    >
    >This is a shot in the dark but -
    >
    >I have some code where I need to use late binding to open a DAO database
    >object using a system DSN. The problem I am having is that on the machine
    >I need to run this code, late binding does not work. So for testing, I

    created
    >a small VB test app with two routines - one that uses early binding and

    one
    >that uses late binding. Both routines work fine on my machine, but only
    >the early binding routine works on the target machine.
    >
    >I have to use late binding because ultimately, this code will be used in
    >a Lotus Notes routine and there is no way to use early binding in Notes.
    >
    >
    >Here are my test routines. The late binding routine is crashing on the

    CreateObject
    >line.
    >
    >
    >Private Sub cmdTestEarly_Click()
    > Dim dbE As DAO.DBEngine
    > Dim ws As DAO.Workspace
    > Dim db As DAO.Database
    > Dim rst As DAO.Recordset
    > Dim strConnect As String
    >
    > Set dbE = New DAO.DBEngine
    >
    > 'On the target machine this message says "Version: 3.51"
    > MsgBox "Version: " & DAO.DBEngine.Properties("Version")
    >
    > Set ws = dbE.CreateWorkspace("", "admin", "", dbUseJet)
    >
    > strConnect = "ODBC;;DSN=testdsn;"
    > Set db = ws.OpenDatabase("", False, True, strConnect)
    >
    > Set rst = db.OpenRecordset( _
    > "select count(*) as numrecs from testtable", _
    > dbOpenSnapshot, dbReadOnly)
    >
    > MsgBox "Records Found: " & Trim(Str(rst("numrecs")))
    >
    > rst.Close
    > Set rst = Nothing
    > db.Close
    > Set db = Nothing
    > ws.Close
    > Set ws = Nothing
    > Set dbE = Nothing
    >End Sub
    >
    >
    >Private Sub cmdTestLate_Click()
    > Dim dbE As Object
    > Dim ws As Object
    > Dim db As Object
    > Dim rst As Object
    > Dim strConnect As String
    >
    > Set dbE = CreateObject("DAO.DBEngine.35") '????Crashes here????
    >
    > Set ws = dbE.CreateWorkspace("", "admin", "", dbUseJet)
    >
    > strConnect = "ODBC;;DSN=testdsn;"
    >
    > Set db = ws.OpenDatabase("", False, True, strConnect)
    >
    > Set rst = db.OpenRecordset( _
    > "select count(*) as numrecs from testtable", _
    > dbOpenSnapshot, dbReadOnly)
    >
    > MsgBox "Records Found: " & Trim(Str(rst("numrecs")))
    >
    > rst.Close
    > Set rst = Nothing
    > db.Close
    > Set db = Nothing
    > ws.Close
    > Set ws = Nothing
    > Set dbE = Nothing
    >
    >End Sub
    >
    >
    >I have searched MDSN and found articles on runtime licensing which said

    to
    >add registry keys and so on. Nothing has worked yet. Does anyone have

    any
    >idea what would cause the late binding not to work?
    >
    >My machine is NT 4, VB6 SP3 and the target machine is Win95 with DCOM95

    and
    >MDAC. Both machines have MDAC 2.1 installed.
    >
    >
    >Thanks,
    >Robert.
    >
    >



  3. #3
    Robert R. Guest

    Re: early/late binding DAO


    Arthur,
    Thanks for the response. I tried what you suggested on my NT machine and
    I get:

    Run=-time error '429':
    ActiveX component can't create object

    Are you sure this is correct?

    Thanks.
    Robert


    "Arthur Wood" <wooda@saic-trsc.com> wrote:
    >
    >Robert,
    > try this change...
    >
    >Set dbE = CreateObject("DAO.DBEngine")
    >
    >that is, do not specify the version of the DEEngine that you want to use.
    >
    >That way you will get whatever version is actually installed on the target
    >machine.
    >
    >Arthur Wood
    >
    >




  4. #4
    Arthur Wood Guest

    Re: early/late binding DAO


    The only other suggestion would be that it would appear the the box where
    you are trying to use the Late Bnding DOES NOT in fat have the correct version
    of DAO installed (and I stand corrected, you should be using the form

    Set dbE = CreateObject("DAO.DBEngine.35"))

    check out this Knowledge base article:

    http://support.microsoft.com/support.../Q197/9/02.ASP

    It seems to address the situation that you are describing.

    Arthur Wood




    "Robert R." <rrichie@hotmail.com> wrote:
    >
    >Arthur,
    >Thanks for the response. I tried what you suggested on my NT machine and
    >I get:
    >
    > Run=-time error '429':
    > ActiveX component can't create object
    >
    >Are you sure this is correct?
    >
    >Thanks.
    >Robert
    >
    >
    >"Arthur Wood" <wooda@saic-trsc.com> wrote:
    >>
    >>Robert,
    >> try this change...
    >>
    >>Set dbE = CreateObject("DAO.DBEngine")
    >>
    >>that is, do not specify the version of the DEEngine that you want to use.
    >>
    >>That way you will get whatever version is actually installed on the target
    >>machine.
    >>
    >>Arthur Wood
    >>
    >>

    >
    >



  5. #5
    Join Date
    Feb 2010
    Posts
    1
    Use this:

    On Error Resume Next
    Set dbE = CreateObject("DAO.DBEngine")
    Set dbE = CreateObject("DAO.DBEngine.35")
    Set dbE = CreateObject("DAO.DBEngine.36")
    On Error GoTo 0

    it will take whatever version is installed in your computer, if you don't have the first one it will try the next one and so on.

    Hope it helps.
    Ivan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center