Consulting

Results 1 to 1 of 1

Thread: Dlookup only works when Access is open

  1. #1
    VBAX Regular
    Joined
    Aug 2012
    Location
    France
    Posts
    13
    Location

    Dlookup only works when Access is open

    Dear members,

    I have an issue with using DLookup for a Access databasefrom Excel. I admit I don’t have much experience but I am using DAO object andworks fine for me using Dlookup, .OpenRecordset, and looping though the recordset with findnext etc. However, for Dloopup it only works when Access is openwhich is not very practical. I get error 2950 on Dlookup. “Application defined or object defined error”. Open Access and it works again?
    I got add the MS Access 16.0 Object Library and the MSDAO 3.6 Object Library. Been searching the net for this particular issue but I don’tsee any reference.

    In summary:
    Public db As DAO.Database
    Public dbT As DAO.RecordSet
    Set db = DBEngine.OpenDatabase("C:\Users\MyName\DBName.accdb")
    Set dbT = db.OpenRecordset("Table1",dbOpenDynaset, dbReadOnly)
    Dim varX as sting

    TiD = "1-123456"
    LookupT = "[Some Type]"
    Criteria = "[Order ID] = '" & TiD &"'"
    with dbT
    varX = DLookup(LookupT, "Table1",Criteria)

    end with

    also db.close does not seem to close Access. Need to close Excel to edit database.

    Thanks and regards
    Alex

    Last edited by AAhrenst; 04-10-2018 at 12:30 PM.

Posting Permissions

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