Hi there,
I have an annoying problem and hope someone could help me.
I created a function which deletes a query and then creates a new one with CreateQueryDef.
When I use this function from the immediate window, it works perfectly with no error. But when I call this function from a field in a query, it gives error 2486 "you can't carry out this action at present time" on this line :
DoCmd.DeleteObject acQuery, "Sales_Query_1"
How come it works when called from somewhere else? I tried calling this function from a form and it works with no error.
''''''''''''''''''''''''''''''''''''''''''''
Function Sales_Values(code)
Dim sql_text As String
Dim rst As Recordset
Dim qry As QueryDef
DoCmd.DeleteObject acQuery, "Sales_Query_1"
sql_text = "sql statement"
Set qry = CurrentDb.CreateQueryDef("Sales_Query_1", sql_text)
Set rst = CurrentDb.OpenRecordset("Sales_query_2")
sales_values = rst.Fields(2).Value
rst.Close
Exit Function
'''''''''''''''''''''''''''''''''''''''''''
Appreciate any help.
Cheers
I have an annoying problem and hope someone could help me.
I created a function which deletes a query and then creates a new one with CreateQueryDef.
When I use this function from the immediate window, it works perfectly with no error. But when I call this function from a field in a query, it gives error 2486 "you can't carry out this action at present time" on this line :
DoCmd.DeleteObject acQuery, "Sales_Query_1"
How come it works when called from somewhere else? I tried calling this function from a form and it works with no error.
''''''''''''''''''''''''''''''''''''''''''''
Function Sales_Values(code)
Dim sql_text As String
Dim rst As Recordset
Dim qry As QueryDef
DoCmd.DeleteObject acQuery, "Sales_Query_1"
sql_text = "sql statement"
Set qry = CurrentDb.CreateQueryDef("Sales_Query_1", sql_text)
Set rst = CurrentDb.OpenRecordset("Sales_query_2")
sales_values = rst.Fields(2).Value
rst.Close
Exit Function
'''''''''''''''''''''''''''''''''''''''''''
Appreciate any help.
Cheers