MS Query

Martin_King

Board Regular
Joined
Jan 20, 2009
Messages
153
Hi all,

I don't know if I'm in the right area for this but I use your site all the time and you manage to answer 99% of my questions. However I've become a bit stuck with setting a parameter in MS Query through excel, and any help would be great.

Basically we query SAGE, and have account codes begining xx-xxx. We use the project ledger which attaches a letter on the end depending on the works, i.e. 00-001A, 00-001B, etc

I need to set a paramater to say any that any that begin/contain (i.e. LIKE %) 00-001 filter out, regardless of the letter.

I know the basics of [paramater] or ?, but the ? doubles as a wildcard in the like criteria. Whenever I try to put a paramter value in it shows nothing. I can get it to work for exact, >< etc but not contains or begins. Even if I play with the SQL, nothing!

Any ideas guys? I'm really at a loose end here??

Thanks for all the help

M
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi Martin & Welcome to the Board!

The criteria in SQl should look like:

Code:
AccountCodeField Like '00-001_'

It is the underscore that functions as a single character wildcard (usually) when using MSQuery. This may depend on what (if any) specific SAGE ODBC driver is being employed though
 
Upvote 0
Try using something like:
WHERE Left(
Code:
,6) = ?
and then you can just use your 00-001 as the parameter.
 
Upvote 0
Thanks for the quick reply.

Richard; I understand about the wildcard, and thats similair to what I am using now to include all the 00-001 and works. What I want is to have a cell where I can enter 00-001, 00-002 etc and it extracts all the info for these codes. At the moment I have to manually edit the query and change the code to 00-002 etc. I can use parameters normally just not in this case

Rorya; can you explain a little more? I have looked at the sql and cant seem to incorporate the Left function.Do you mean WHERE (prtrm.project=LEFT(
Code:
,6)=?)
I have tried this and can't seem to get it to work? I may be missing something, I don't know.
 
Thanks for all the help so far!! Fingers crossed
 
Upvote 0
Nope:
WHERE left(prtrm.project,6)=?
should work if I understand you correctly
 
Upvote 0
Rorya, your a diamond!! Works like a charm. I had know idea you can combine formula with the criteria. This may help solve some minor bugs in my other queries where I have had to use a work around solution.

Thanks for all the time and help all. You can close the thread now (or however it works) :rolleyes:
 
Upvote 0
Using Like can offer you a deal of flexibility though - you can set your criteria up as:

Code:
WHERE AccountCode Like ?

and then you should get the dialog asking you to fill in the criteria. You just need to remember to use _ as the wildcard for single character
 
Upvote 0
Richard,

Ive tried combinations of what you suggect but It wont accept the parameter. This is my sql

SELECT prtrm.project, prtrm.expense_code, prtrm.period, prtrm.trans_reference, prtrm.description, prtrm.amount, prtrm.glcode
FROM ffclubs.scheme.prtrm prtrm
WHERE (prtrm.glcode Like '00-001%') AND (prtrm.period<='200903')

This works with 00-001
If i try replacing this with;
'?'
'
Code:
'
'[code?]
or 
(prtrm.glcode='Like?') or 'Like ?' i get nothing. It doesn't even ask me to enter anything, just returns blanks. Im adament there is a way to det a like parameter but I've googled and googled to no joy.
 
Rorya's solution is working but if you know where I'm going wrong then it would be a great help as I have many other minor issues that this can help with
 
Upvote 0
WHERE (prtrm.glcode Like ?)
but you would then have to include the % (or underscore) when entering the parameter.
 
Upvote 0
Rorya

Got it to work! Genius. Ive adapted the cell ref to include the wildcards so the user can just type the code.

Thanks for all the help
 
Upvote 0

Forum statistics

Threads
1,216,970
Messages
6,133,806
Members
449,834
Latest member
Damien Hartzell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top