INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Access pass-through query using a form for parameter

Access pass-through query using a form for parameter

(OP)
I am using Access 2010 and am trying to execute a pass through query from a form where a date in entered. The query looks like this:

SELECT RTRIM(name.last_name) +', ' + name.first_name AS Name, name.soc_sec AS ID, address.st_addr, address.add_addr,RTRIM( address.city) + ', ' + address.state + ' ' + address.zip AS CtySTZip, address.e_mail, address.e_mail2, address.phone, address.cell_phone, nmprg.prg_cod, dispos.disp_date, approg.entry_date
FROM name, address, nmprg, dispos, approg
WHERE approg.entry_date = [Forms]![ParameterForm]![EntryDate]
AND name.soc_sec = address.soc_sec
AND name.soc_sec = nmprg.soc_sec
AND name.soc_sec = dispos.soc_sec
AND name.soc_sec = approg.soc_sec
AND address.preferred = '1'
AND nmprg.active = '1'
AND dispos.CurDispos = '1'
AND dispos.dispos in ('Depostied', 'Enrolled')

I get ODBC - call failed. Incorrect syntax near '!' (#102).

What am I doing wrong? Is there a better way to pass a parameter?

RE: Access pass-through query using a form for parameter

It looks good to me. I always use & in Access, not +. I doubt that would make a difference though.

RE: Access pass-through query using a form for parameter

(OP)
Any idea why it does not like the approg.entry_date = [Forms]![ParameterForm]![EntryDate] statement?

RE: Access pass-through query using a form for parameter

"query from a form " - just a guess here...
If your Select statement is in the Form, so it is in the code, right?

Does it look like:

strSQL = "Select RTRIM(name.last_name) +', ' + name....."

???

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: Access pass-through query using a form for parameter

(OP)
The form has a Text Box for the person to enter the date. They then click on a button that has an event to run the query.

RE: Access pass-through query using a form for parameter

...and you must CONVERT your date STRING on your form to a date NUMBER in the query...

CODE

WHERE approg.entry_date = #[Forms]![ParameterForm]![EntryDate]# 
...assuming that the user had entered a valid date string

RE: Access pass-through query using a form for parameter

(OP)
It is formated as 'Short Date'. The field I am comparing it to is a date time field. How can I change it to only date, I tried date(approg.entry_date) but access didn't like that.

RE: Access pass-through query using a form for parameter

Int(Entry_date) = .....

RE: Access pass-through query using a form for parameter

(OP)
I received the error message 'Int' is not a recognized built-in function name. (#195)

RE: Access pass-through query using a form for parameter

okay then..

CODE

WHERE approg.entry_date => #[Forms]![ParameterForm]![EntryDate]# 
  AND approg.entry_date < #[Forms]![ParameterForm]![EntryDate]# + 1 

RE: Access pass-through query using a form for parameter

(OP)
Received Incorrect syntax near '>'. (#102)

RE: Access pass-through query using a form for parameter

Post your code

RE: Access pass-through query using a form for parameter

(OP)
SELECT RTRIM(name.last_name) +', ' + name.first_name AS Name, name.soc_sec AS ID, address.st_addr, address.add_addr,RTRIM( address.city) + ', ' + address.state + ' ' + address.zip AS CtySTZip, address.e_mail, address.e_mail2, address.phone, address.cell_phone, nmprg.prg_cod, dispos.disp_date, approg.entry_date
FROM name, address, nmprg, dispos, approg
WHERE approg.entry_date => #[Forms]![ParameterForm]![EntryDate]#
AND approg.entry_date < #[Forms]![ParameterForm]![EntryDate]# + 1
AND name.soc_sec = address.soc_sec
AND name.soc_sec = nmprg.soc_sec
AND name.soc_sec = dispos.soc_sec
AND name.soc_sec = approg.soc_sec
AND address.preferred = '1'
AND nmprg.active = '1'
AND dispos.CurDispos = '1'
AND dispos.dispos in ('Depostied', 'Enrolled')

RE: Access pass-through query using a form for parameter


CODE

WHERE approg.entry_date >= #[Forms]![ParameterForm]![EntryDate]# 
  AND approg.entry_date < #[Forms]![ParameterForm]![EntryDate]# + 1 

RE: Access pass-through query using a form for parameter

(OP)
Now I get Incorrect syntax near 'Forms'. (#102)

RE: Access pass-through query using a form for parameter

(OP)
If I put the statement in quotes like this:
WHERE approg.entry_date >= '#[Forms]![ParameterForm]![EntryDate]#'
AND approg.entry_date < '#[Forms]![ParameterForm]![EntryDate]#' + 1
I get Conversion failed when converting date and/or time from character string (#241)

RE: Access pass-through query using a form for parameter

A pass-through sends the complete SQL statement to the SQL Server which has no idea what the your parameterform or controls are. You need to use a little VBA/DAO code to set the SQL property of the saved P-T query. Check the FAQs of this forum for a simple function that allows you to change the SQL of a saved query.

Duane
Hook'D on Access
MS Access MVP

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close