Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access pass-through query using a form for parameter

Status
Not open for further replies.

Cozmo2

Technical User
Apr 7, 2006
87
US
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?
 
It looks good to me. I always use & in Access, not +. I doubt that would make a difference though.
 
Any idea why it does not like the approg.entry_date = [Forms]![ParameterForm]![EntryDate] statement?
 
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:
[tt]
strSQL = "Select RTRIM(name.last_name) +', ' + name....."[/tt]
???

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.
 
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.
 
...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
 
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.
 
I received the error message 'Int' is not a recognized built-in function name. (#195)
 
okay then..
Code:
WHERE approg.entry_date => #[Forms]![ParameterForm]![EntryDate]# 
  AND approg.entry_date < #[Forms]![ParameterForm]![EntryDate]# + 1
 
Received Incorrect syntax near '>'. (#102)
 
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')
 

Code:
WHERE approg.entry_date >= #[Forms]![ParameterForm]![EntryDate]# 
  AND approg.entry_date < #[Forms]![ParameterForm]![EntryDate]# + 1
 
Now I get Incorrect syntax near 'Forms'. (#102)
 
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)
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top