Results 1 to 5 of 5
  1. #1
    JamieGMN is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Location
    Minnesota
    Posts
    3

    error when utilizing a call function in query criteria

    I want to use a simple call function in the criteria of the query and I keep getting "Unknown Access database engine error"



    Public call function is simple:


    dim gdtmSpecDate as Date

    Function getSpecDate() As Date
    getSpecDate = gdtmSpecdate
    End Function

    I then incorporate into a query criteria as getSpecDate()

    the crazy is the query design even pulls up my list of defined functions and plugs it in with one "(" and when I check the function in the debug it works fine - but then when I open query it sates "Ukown Access database engine error"

    any help appreciated

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Grasping at straws here...

    Can you post your sql? Maybe a syntax error?
    Have you initialized a value in gdtmSpecDate?
    Tried a compact & repair?

  3. #3
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Is the function in a standard module (correct) or a form module (incorrect)? Can you change the declaration of the variable from Dim to Public?

    Code:
    Public gdtmSpecDate as Date
    
    Function getSpecDate() As Date
    getSpecDate = gdtmSpecdate
    End Function
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    JamieGMN is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2021
    Location
    Minnesota
    Posts
    3
    All Thanks for trying to help a novice. Here is what I have found. If I open the query on its own with the getSpecDate() in the criteria section it opens correctly with no errors. If I open a form and initiate VBA code to pass a value into gdtmSpecDate and then try to utilize the query while in the macro, such as opening the query as a recordset that is where I get the error from the query. It is very strange to me that while I am utilizing macros in forms that it corrupts the ability of public module to work. Related for some reason values passed into the public global variables do not seem to be sticking once teh event driven VBA sub routine is exited. I am wondering if there is some nuance to labeling seetings of my code associated with my class objects vs modules? Below is my specific code within the form - pretty straightforward cannot see why it would prevent query from accessing the public routing "getSpecDate()"

    Private Sub CmdImportdata_Click()
    Dim db As Database
    Dim rst As Recordset


    'Routine to check if data already exists in table before importing


    Set db = CurrentDb()
    Set rst = db.OpenRecordset("qryTempTblImport", dbOpenDynaset)
    'get date of first data in the Temporary Data table containtnig raw import data
    rst.MoveFirst
    gdtmSpecDate = rst![TipDate]
    Debug.Print gdtmSpecDate
    Debug.Print getSpecDate()
    rst.Close

    'open query of Permanent data and look for equivalent date using GetSpecDate() in the criteria
    Set rst = db.OpenRecordset("qryTipDataMatch", dbOpenDynaset)
    If rst.RecordCount > 0 Then
    MsgBox "There are no files to Import"
    exitSub
    End If

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try doing away with the variable and use the recordset field directly:

    'dim gdtmSpecDate as Date


    Function getSpecDate(dArg as date) As Date
    getSpecDate = dArg
    End Function


    Then in the query

    getSpecDate(rst!TipDate)

    Another possibility, set a tempvar = rst!tipdate,
    then the tempvar can be used in the query, no function required.
    Last edited by davegri; 03-25-2022 at 03:57 PM. Reason: added tempvar suggestion

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

Similar Threads

  1. Replies: 6
    Last Post: 01-23-2024, 09:04 PM
  2. Function call in query slowing it down
    By sneuberg in forum Queries
    Replies: 2
    Last Post: 10-17-2014, 10:32 AM
  3. Replies: 2
    Last Post: 11-04-2011, 02:45 AM
  4. Silly error on a simple function call - help
    By allenjasonbrown@gmail.com in forum Programming
    Replies: 5
    Last Post: 06-10-2011, 01:23 PM
  5. Replies: 4
    Last Post: 11-06-2009, 09:51 AM

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