Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6349305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:23+00:00 2026-05-24T21:35:23+00:00

I’m assigning an Access 2007 query to a QueryDef in Excel VBA. My query

  • 0

I’m assigning an Access 2007 query to a QueryDef in Excel VBA. My query calls a user-defined function, because it performs a calculation on the results of evaluating a field with a regular expression. I’m using a QueryDef because I’m collecting values in a UserForm and want to pass them to the query as parameters.

When I run my VBA code, I get an error: “Run-time error ‘3085’: Undefined function ‘regexFunc’ in expression.”

This question suggests that the problem is that DAO is unable to call Access UDFs from Excel, so I copied my UDF into the Excel VBA module, but I still get the error.

Access query:

select field1 from dataTable where regexFunc(field1)=[regexVal]

Here’s the Excel VBA code:

'QueryDef function
Sub makeQueryDef (str As String)

Dim qdf As QueryDef
Dim db As Database

Set db = OpenDatabase(DBpath)
Set qdf = db.QueryDefs("paramQuery")
qdf.Parameters("regexVal") = (str="test")
doSomething qdf

End Sub

'Regex function copied from Access VBA module to Excel VBA module
Function regexFunc(str As String) As Boolean

Dim re As RegExp
Dim matches As MatchCollection

regexFunc = False
Set re = New RegExp
re.Pattern = "\reg[ex](pattern)?"
Set matches = re.Execute(str)
If matches.Count <> 0 Then
    regexFunc = True
End If

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:35:23+00:00Added an answer on May 24, 2026 at 9:35 pm

    I’ve solved this. Here’s how I did it.

    First I change the query into a recordset and pass it to my filtering function:

    function filteredQDF(qdf As QueryDef, boolVal As Boolean) As Variant
    
    Dim rs As Recordset
    Dim rows_rs As Variant
    Dim rs_new As Recordset
    Dim filtered As Variant
    
    
    Set rs = qdf.OpenRecordset
    
    rs.MoveLast
    rs.MoveFirst
    
    rows_rs = rs.GetRows(rs.RecordCount)
    rows_rs = Application.WorksheetFunction.Transpose(rows_rs)
    filtered = filterFunction(rows_rs, boolVal)
    
    filteredQDF = filtered
    
    End Function
    

    And here’s the filtering function, which creates a new array, populates it with rows that pass the UDF’s boolean check, and returns it:

    Function filterFunction(sourceArray As Variant, checkValue As Boolean) As Variant
    
    
    Dim targetArray As Variant
    Dim cols As Long
    Dim targetRows As Long
    Dim targetCursor As Long
    
    
    'get # of columns from source array
    cols = UBound(sourceArray, 2)
    
    'count total number of target rows because 2D arrays cannot Redim Preserve
    'checking sourceArray(r,2) because that's the criterion column
    targetRows = 0
    For r = 1 To UBound(sourceArray, 1)
        If myUDF(CStr(sourceArray(r, 2))) = checkValue Then
            targetRows = targetRows + 1
        End If
    Next
    
    'set minimum target rows to 1 so that function will always return an array
    If targetRows = 0 Then
        targetRows = 1
    End If
    
    'redim target array with target row count
    ReDim targetArray(targetRows, cols)
    
    'set cursor for assigning values to target array
    targetCursor = 0
    
    
    'iterate through sourceArray, collecting UDF-verified rows and updating target cursor to populate target array
    For r = 1 To UBound(sourceArray, 1)
        If myUDF(CStr(sourceArray(r, 2))) = checkValue Then
            For c = 1 To cols
                targetArray(targetCursor, c - 1) = sourceArray(r, c)
            Next
            targetCursor = targetCursor + 1
        End If
    Next
    
    
    'assign return value
    filterFunction = targetArray
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.