I have an access request that requests a value that needs to be set in a combo box in a form in order to work
Criteria: Forms![_SelectCustomer]![CmbSelectCustomer]
So far so good, however, I would like the request to open, read and close this form programmatically when it is run using a macro.
I am following @ David-W-Fenton's answer to an IT similar stack overflow question and came up with the following code:
Public Function rtnSelectCustomer() As Variant DoCmd.OpenForm "_SelectCustomer", , , , , acDialog With Forms![_SelectCustomer] If .Tag <> "Cancel" Then rtnSelectCustomer = Nz(!CmbSelectCustomer, "*") Else rtnSelectCustomer = "*" End If End With Close acForm, "_SelectCustomer" End Function
I call this function from the criteria field of the property that I want to filter in Query:
Like rtnSelectCustomer()
At this moment, I am facing several problems:
First, I’m not sure where to place the actual code: I can’t create a specific class or module for my request in the “Microsoft Access Class Objects” folder, so I resorted to creating my own module in the “Modules” folder. (Is it correct?)
The second problem is that when I run a query with the code in the current module that I created, I get the following error:
Runtime Error "2486": You cannot complete this action at this time.
Any advice would be highly appreciated
Edit:
I should clarify that after further testing, a line that seems to cause a runtime error is as follows:
DoCmd.OpenForm "_SelectCustomer", , , , , acDialog
The function is actually called replacing the internal code with the following: it really works (although, admittedly, it's useless)
Public Function rtnSelectCustomer() As Variant rtnSelectCustomer End Function