How to prompt user for parm value from module

Posted on 2006-03-27
Last Modified: 2011-10-03
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)
    Next param
    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"
Question by:xhat
    LVL 27

    Accepted Solution

    use the Inputbox

    YourParm =inputbox("what is the value you want to enter")

    then YourParm have the value you want , and you can use it in your code.


    Author Comment

    Of course! How obvious.  Thanks for showing me the forest. The trees were in the way.
    LVL 27

    Expert Comment

    it must have been foggy too :o)

    you are welcome,
    thanks for the points and the grade


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now