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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Query Criteria by Form

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
I have used the Query by Form often to pass single value criteria to a query.&nbsp;&nbsp;I am now trying to pass multiple values (text) but can't seem to figure out the syntax.<br><br>I have a series of reports based on Diagnostic Codes and would like to set up a master query and pass the appropriate Diagnostic Codes to that query based on the user selection of report type.<br><br>I put the code in the On Click event for the report preview just before the DoCmd to run the preview.&nbsp;&nbsp;If I pass a single value I receive the expected results; however, when I try to pass multiple values I get zip.<br><br>I've tried txtDxCode =&quot;304.00 or 304.01 or 304.91&quot;. <br><br>I've tried building the string one element at a time and that doesn't seem to work either<br><br>I've even tried using triple quote marks around the Dx codes to force the string to contain quotes around each element.<br><br>When I look at the string in debug and it &quot;looks&quot; ok.<br><br>So, the question is:&nbsp;&nbsp;How do you pass multiple OR values to a query from a form?<br><br>Thanks.<br><br><br> <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
Are the users keying in these values? Or are they picking them from somewhere?<br><br>Go to the SQL of your query, copy it, & paste it here, that will help. <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Thanks for the reply, Jim.<br><br>The values I am passing, when I look at them in debug, don't look too much like the SQL code.&nbsp;&nbsp;However, I'm not setting up an SQL string but passing the values to the criteria cell in a Query.<br><br>I'm passing the values via VBA using the On-Click event for a command button that runs the query.<br><br>As I said, if I pass a single value it works fine.&nbsp;&nbsp;It's only when I try to pass multiples via code that I get an empty record set.&nbsp;&nbsp;<br><br>The criteria line in the query references a text field on my form; I set the value of that text field in the code as:&nbsp;&nbsp;txtDxCode = &quot;304.00 Or 304.01 Or 304.19&quot;.<br><br>I tried embedding quotes in the string using this:&nbsp;&nbsp;<br>txtDxCode = &quot;&quot;&quot;304.00&quot;&quot; Or &quot;&quot;304.01&quot;&quot; Or &quot;&quot;304.19&quot;&quot;&quot;<br>Thinking that I needed the string to contain quote marks just like a query adds in text fields -- didn't work.<br><br>Seems to me that one of those should work but . . . <br><br>Maybe you can shed some light on this for me.<br><br>Thanks. <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
My question is: How is the user going to enter multiple values? <br><br>In a single text box, like; 304.00, 304.01, 304.19 ?<br>In multiple text boxes ?<br><br>I need to know how you are going to get the values you need.<br><br>BTW: Your SQL statement should read as follows:<br><br>SELECT .......<br>FROM .....<br>WHERE(((DxCode) = '304.00') OR ((DxCode) = '304.01') OR ((DxCode) = '304.19'))<br>ORDER BY .....;<br><br>I know all about the codes your talking about (DX & CPT). I was in the medical industry for 7 years, and developed a Healthcare Application called Organizational Management System (OMS). It handled Eligibility, referrals, Case Mgmt, and Physician Credentialing.<br><br>If you could give me a little background on what the user will be doing to request this query, I could give you a specific answer. Like: On a form the user enters Dx codes into multiple text boxes (max. of 5), clicks a button, and ...... etc.<br> <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Hi Jim:<br><br>The purpose of the report is to produce a list of residents (query result) who have the requested Dx.<br><br>I set up a form that allows user to specify a Starting Month and Year and Ending Month and Year with a &quot;Set Dates&quot; command button that assigns the correct date values to two text boxes.&nbsp;&nbsp;The user then selects the desired Dx category by clicking on a report command button; the VBA code for that button sets the value of a hidden text box (txtDxCode) to a string containing the appropriate Dx codes as I described above.<br><br>The command button then invokes the query for that specific Dx.&nbsp;&nbsp;In the underlying query I have set the criteria to reference the values:&nbsp;&nbsp;[Forms]![frmDxMaster]![txtDxCode] for the specified Dx codes.&nbsp;&nbsp;The date range is passed the same way.<br><br>As I said, if I pass a single value this way it works fine.&nbsp;&nbsp;If I pass multiples with an OR it displays a query with no records.<br><br>I'm sure that the problem is in the way I create the string; some silly syntax thing that I can't seem to figure out.<br><br>Thanks for taking the time to assist me with this, I really appreciate it. <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
I suggest you see the Buildcriteria method it will take a string and convert it into proper syntax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top