How to prompt user for parm value from module
Posted on 2006-03-27
I've found stuff all over the Internet that hits around my question, but nothing that directly addresses the issue. I have a module that I'm using to output a text file. Part of the data that is output is going to come from a parameter query I've built. My goal is to be able to simply run the module and be prompted for the parameter. Most of what I've read deals with getting the parameter value from a form, but in this case, a form is neither necessary nor desired. The module and db will only ever be used/accessed by myself and my boss. I've fiddled with the code (both DAO and ADO methods) to open the query and pass it the parameter value, but I keep running into errors. The primary one being "Object variable or With Block variable not set." Below is the current state of my code.
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
Dim param As ADODB.Parameter
'Dim qry As DAO.QueryDef
' Dim db As DAO.Database
'Dim parm As DAO.Parameter
'Dim rst As DAO.Recordset
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "GET_TMFR_DATA" 'name of param query
For Each param In cmd.Parameters
param.Value = Eval(param.Name)
Set rst = cmd.Execute(cmd.CommandText, param)
'Set qry = db.QueryDefs("GET_TMFR_DATA")
'qry.Parameters(0) = "FS06"
'Set rst = qry.OpenRecordset
The lines that are commented out are the DAO method which yields the error "Object variable or With Block variable not set.
The ADO method yields the error "Invalid SQL statement; expected DELETE, INSERT, PROCEDURE, SELECT, or UPDATE statement"