variables for query criteria

  • Thread starter Thread starter zSplash
  • Start date Start date
Z

zSplash

I want to get input for query criteria. Here's the code I'll use to get the
input:
Dim BegD As Date, EndD As Date, Inv As String
BegD = InputBox("Enter beginning date", , "010105") 'Date)
EndD = InputBox("Enter ending date", , "123105") 'Date)
Inv = Left(LCase(InputBox("Enter investigator's first name", ,
"Peter")), 1)
...
Now, how do I insert the variables' values into the criteria of the query?

TIA
 
You would be better off creating a form to accept the dates and name.
Then have a button on the form which runs the query, you then refer to the
parameters in the query with syntax [Forms]![Formname]![Controlname]

Incidentally, your inputbox code is fraught with problems such as you have
defined the dates as date type, so if the user enters an invalid date you
will raise an error.

-Dorian
 
Thanks, Dorian, for responding. (I have more code that overcomes the input
errors you mention.) I will try what you suggest, but sure seem to be
spending a lot of time/effort trying to do something that seems so simple...
(:?)

I'm wondering how difficult it is to put input into a parameter query, such
as:
1. >[Enter beginning date:] & "*"
2.<[Enter ending date:] & "*"
3.=[Enter guy's name] & "*"

st.

mscertified said:
You would be better off creating a form to accept the dates and name.
Then have a button on the form which runs the query, you then refer to the
parameters in the query with syntax [Forms]![Formname]![Controlname]

Incidentally, your inputbox code is fraught with problems such as you have
defined the dates as date type, so if the user enters an invalid date you
will raise an error.

-Dorian

zSplash said:
I want to get input for query criteria. Here's the code I'll use to get
the
input:
Dim BegD As Date, EndD As Date, Inv As String
BegD = InputBox("Enter beginning date", , "010105") 'Date)
EndD = InputBox("Enter ending date", , "123105") 'Date)
Inv = Left(LCase(InputBox("Enter investigator's first name", ,
"Peter")), 1)
...
Now, how do I insert the variables' values into the criteria of the
query?

TIA
 
I have created a form, as you say, with a button to run the query, but still
don't know where/how to put parameter values into the query. On the open
event of the form, I can get the values for the variables, but what do you
mean by "refer to the parameters in the query with syntax
[Forms]![Formname]![Controlname]" Sorry I'm so dumb, but I just don't get
it.

TIA

mscertified said:
You would be better off creating a form to accept the dates and name.
Then have a button on the form which runs the query, you then refer to the
parameters in the query with syntax [Forms]![Formname]![Controlname]

Incidentally, your inputbox code is fraught with problems such as you have
defined the dates as date type, so if the user enters an invalid date you
will raise an error.

-Dorian

zSplash said:
I want to get input for query criteria. Here's the code I'll use to get
the
input:
Dim BegD As Date, EndD As Date, Inv As String
BegD = InputBox("Enter beginning date", , "010105") 'Date)
EndD = InputBox("Enter ending date", , "123105") 'Date)
Inv = Left(LCase(InputBox("Enter investigator's first name", ,
"Peter")), 1)
...
Now, how do I insert the variables' values into the criteria of the
query?

TIA
 
Back
Top