Results 1 to 7 of 7
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Run-time error '3075'

    Having a problem with this connecting to Access
    Code:
    Function Dlookup(Field, Domain, Criteria) As String
        Dim r As DAO.Recordset
        Dim sql As String
        sql = "Select " & Field & " from " & Domain & " Where " & Criteria
        With MyCurrentDB.CreateQueryDef("", sql)
            Set r = .OpenRecordset
                If r.RecordCount > 0 Then
                    Dlookup = r(0)
                    .Close
                End If
            Set r = Nothing
        End With
    End Function
    
    
    Function MyCurrentDB() As DAO.Database
        Set MyCurrentDB = DAO.OpenDatabase("C:\DB\Test.mdb")
    End Function
    I use it in VB6 and just ported it into Excel but get
    Run-time error '3075':


    Application-defined or object-defined error
    I suspect References and have Microsoft DAO 3.6 Object Library but do I need something else?
    Or have mucked something in the code ?

    Thanks

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I thought Microsoft Office ##.# Object Library might be required in Excel for this but apparently it is not. If you are running the second code first, be aware that With MyCurrentDb will probably call it a second time. Probably not your issue though. Maybe you selected the library by clicking on the line in the dialog but forgot to check the box?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    What line creates the error?

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Function Dlookup(field, domain,criteria) is trying to create a UDF.
    The Dlookup function already exists in Access. Try changing the UDF name.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Function Dlookup(field, domain,criteria) is trying to create a UDF.
    That code works for me as long as I have a reference to DAO (and a valid file path), so while it's not good, it's not the problem if the code is in Excel. That's not entirely clear but it's how I interpret the op.
    Last edited by Micron; 11-10-2023 at 10:10 AM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    sql = "Select " & Field & " from " & Domain & " Where " & Criteria
    Hope you don't use spaces or non alpha numeric characters in your database table and field names, otherwise this sql will fail

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    WRT spaces it will work if the table name is enclosed in brackets so I suppose the field or criteria would work with spaces also. Using a posted db from another thread:

    Dlookup"PaymentMethodID","[Payment Methods]","PaymentMethod = 'Quit'"
    7
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 12-24-2021, 02:28 AM
  2. Replies: 6
    Last Post: 02-03-2020, 07:09 PM
  3. Replies: 13
    Last Post: 05-31-2019, 10:48 PM
  4. Replies: 2
    Last Post: 01-04-2016, 09:40 AM
  5. Replies: 6
    Last Post: 05-30-2012, 12:32 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
  •  
Other Forums: Microsoft Office Forums