Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

DEFAULT VALUES IN PARAMETER QUERIES

i got this tip in my email, but I do not know where to add this code. In the form? Query? help!




And now for today's tip...          
           
DEFAULT VALUES IN PARAMETER QUERIES            
   
Paul Fantacci of Maryland sent a great tip for using default values in
parameter queries. In general, you can't specify a default value for a
parameter in query. For instance, let's suppose you use the same
parameter query to check sales by region. When you run the query, the
parameter expression prompts you for a region. You enter a region, and
Access then displays the results for that region.  

Let's suppose you run this query for one particular region most of the
time. In that case, it would be nice if your parameter query would
default to that region. Then you could run it by accepting the
default--changing it only when you need to see the sales totals for
another region.  

Paul Fantacci explains that if you use the InputBox function in your
parameter expression in the form

Eval("InputBox(""prompt:"",""title"",""defaultvalue"")")

Access displays an input box instead of the normal parameter prompt.
If you click OK, Access runs the query using defaultvalue as the
query's criteria. Or you can enter a new value, then click OK to run
the query.  

TK
0
TK421
Asked:
TK421
  • 11
  • 5
  • 5
1 Solution
 
nico5038Commented:
Should work in both form rowsource and in query criteria, as both support functions!

But why doesn't give it a try?

On the other hand, normally I don't want this as I like to fill the values from my form, thus not bothering the user with (a lot of) propmts, that he has to OK or Cancel!
0
 
TK421Author Commented:
I imagine I need to replace some of the text in the line, but what text?

I have a query prompt me for a "ChargeCode". Where would I enter that in this line of text? Once I get the code correct, I'll try and place it in the Row Source. Thx.
0
 
paaskyCommented:
Hello TK421,

As nico5038 said, you can use this in your queries, which you can use as Recordsource with your reports and forms and queries which update or delete data.

For eg. this query would be used with your report or form (written in Query SQL view window):

SELECT *
FROM tblCustomer
WHERE CustomerName=Eval("InputBox(""Enter customer name:"",""Choose customer"",""TK421"")");

Regards,
Paasky
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
nico5038Commented:
Place in the query criteria cell below the ChargeCode:

Eval("InputBox(""ChargeCode:"",""Form for inputting ChargeCode"",""12345"")")

""ChargeCode:"" is the text in front of the input field
""Form for inputting ChargeCode"" is the title in the blue title bar of the form
""12345"" is a default value that you can set to support the user by giving him the most used value.
0
 
TK421Author Commented:
Looks like it's working. Sort of. I need to be able to wildcard (*)

Heres's my criteria now:

Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""8FBAJ"")")

How can I get results like:

8fbaj-lt1
000-8fbaj-lt2
05-8fbaj

Right now I only get "8fbaj". Thanks!
0
 
paaskyCommented:
SELECT *
FROM table1
WHERE ChargeCode LIKE Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""*8FBAJ*"")");

0
 
nico5038Commented:
Just take the wild-characters section from the help file and put in (under a help-button?) on the creen for your user(s).

Not only the "*" but also the "?" and the "[1-4]" examples are usefull.
0
 
TK421Author Commented:
Any ideas paasky?
0
 
TK421Author Commented:
I get no results when I try this:

Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""*8FBAJ*"")")


OR when I try and wildcard in the prompt.....    :..(

TK421
0
 
TK421Author Commented:
I get no results when I try this:

Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""*8FBAJ*"")")


OR when I try and wildcard in the prompt.....    :..(

TK421
0
 
TK421Author Commented:
Adjusted points from 30 to 60
0
 
TK421Author Commented:
Pts raised to 60.
Let's kick it up a notch! Again, I can not get the wildcard in the code or when entering it manually. Any ideas anyone? Thanks for all of the great advice.

TK421
0
 
paaskyCommented:
dear TK421,

Where/how are you using the function? I tried exactly same query that I posted here and got just the records what should come.

If you have a query there would you please post it here and I'll look what's the problem. Also you should modify your query in SQL view instead of Design view.

And you can always email part of your db to me... ;-)

Regards,
Paasky
0
 
TK421Author Commented:
This function is placed in the query criteria. This DOES NOT return any records:

Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""*8FBAJ*"")")

But this does:

Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""8FBAJ"")")

I also tried to edit the SQL and I get the same results. ANy ideas?

Is there another place I can try this code? I have a form (in datasheet view). Would it work there?

Thanks!
0
 
paaskyCommented:
You should use operator LIKE. Put this into query criteria:

Like Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""*8FBAJ*"")")

and it should work.

This is from Access help:
You can use the Like operator to find values in a field that match the pattern you specify. For pattern, you can specify the complete value (for example, Like "Smith"), or you can use wildcard characters to find a range of values (for example, Like "Sm*").

Paasky
0
 
nico5038Commented:
Still asking myself why you want the values entered this way. When a user enters the string in a text field on your form you can add the "*"'s by code and the user can't mess it up ?!
Also multiple fields are posible from the form, with EVAL you will have to press OK for each variable as on the form just once!
0
 
TK421Author Commented:
Yes! That's exactly what I want. Thank you Paasky. AGAIN!

As far as why I want this:
I want the DB to return all instances of fields containing *xxx*. I do not want to leave it to the user to enter the (*) manually.

Thanks paasky!
0
 
paaskyCommented:
Happy to help you TK.

Best regards,
Arto
0
 
TK421Author Commented:
paasky,

It runs fine. But when I click the "cancel" button, it runs and returns no records. Why? aaahhhh!
0
 
TK421Author Commented:
paasky,

It runs fine. But when I click the "cancel" button, it runs and returns no records. Why? aaahhhh!
0
 
nico5038Commented:
Sorry TK421, I don't get it.

The EVAL gives an input box, thus the user can type what he wants with or without "*" ?!
shouldn't it look like:
Like '*" & Eval("InputBox(""ChargeCode:"",""Status by Charge CodeForm"",""8FBAJ"")") & "*'"

To force to have always "*"'s around the string?
 


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 11
  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now