UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Select query using IN    
 
   
CHKarcher
post Nov 4 2008, 11:24 AM
Post #1

UtterAccess Veteran
Posts: 450
From: Oklahoma



Try to us my SQL knowledge in selecting a group of data contain a selected group of Chcek Numbers. I have a text box on a form that a user can enter in chcek numbers example:

10023, 10045, 10089


I am try to have my query look at this field and only pull thoe 3 numbers


SQL
----
Select * from q_Table1 where checknumber in ('10023','10045','10089')

But how do I make Access Query look at the form field?

thanks
steve
Go to the top of the page
 
+
R. Hicks
post Nov 4 2008, 11:42 AM
Post #2

UA Forum Administrator
Posts: 38,073
From: Birmingham, Alabama USA



It should be something like:

Forms![YourFormName]![YourControlName]

RDH
Go to the top of the page
 
+
CHKarcher
post Nov 4 2008, 12:05 PM
Post #3

UtterAccess Veteran
Posts: 450
From: Oklahoma



In the check number criteria if type

IN(10016,10034,10054) IT WORKS!

but if I use the form

IN(Forms![Form1]![CheckLookup])

it says that is to complicated of a query - No Workie.

ideas?
TIA
steve
Go to the top of the page
 
+
CHKarcher
post Nov 4 2008, 12:08 PM
Post #4

UtterAccess Veteran
Posts: 450
From: Oklahoma



It works if I just have one value in the Form Textbox - but when I put in two seperarted by column - it breaks

thanks
steve
Go to the top of the page
 
+
R. Hicks
post Nov 4 2008, 01:06 PM
Post #5

UA Forum Administrator
Posts: 38,073
From: Birmingham, Alabama USA



I don't think that what you are trying to do will work as Access will see the entry in the textbox you are referencing as one singe criteria entry instead of multiple entries seperated by a comma ...
I have created criteria statements using the IN clause .. but the SQL was created dynamically using VBA code and the IN clause was created programically in the code.

RDH
Go to the top of the page
 
+
CHKarcher
post Nov 4 2008, 01:54 PM
Post #6

UtterAccess Veteran
Posts: 450
From: Oklahoma



Can you pass that along (programically code) - and I'll give that a shot.

thanks
steve
Go to the top of the page
 
+
R. Hicks
post Nov 4 2008, 02:18 PM
Post #7

UA Forum Administrator
Posts: 38,073
From: Birmingham, Alabama USA



I don't know if this will help you ... I had a hard time locating the application where I used the code.
Here is the relevent code that created the dynamic IN clause ...

CODE
' Search By Invoice Number(s)

If Len(Me.txtInvoiceNo & vbNullString) > 0 Then

  strTmp = RTrim(IIf(Right(Me.txtInvoiceNo, 1) = ",", _

   Left(Me.txtInvoiceNo, Len(Me.txtInvoiceNo) - 1), Me.txtInvoiceNo))

  strWhere = "WHERE InvoiceNo IN('"

  strTmp = Replace(strTmp, ",", ", ")

  strWhere = strWhere & Replace(strTmp, "', '", ",") & "') "

End If

InvoiceNo is a text datatype in the database.
This allowed the user to enter multple entries seperarted by a comma in a txtbox in a form and the code converted the entry(s) and inserted them into the WHERE of the SQL in the vba code.


RDH
Go to the top of the page
 
+
CHKarcher
post Nov 4 2008, 04:32 PM
Post #8

UtterAccess Veteran
Posts: 450
From: Oklahoma



So would the from code pulling the query would it be

"select * from InvoiceTBL " & strWhere

steve
Go to the top of the page
 
+
R. Hicks
post Nov 4 2008, 04:36 PM
Post #9

UA Forum Administrator
Posts: 38,073
From: Birmingham, Alabama USA



Yes .. that should work ..

RDH
Go to the top of the page
 
+
CHKarcher
post Nov 4 2008, 05:26 PM
Post #10

UtterAccess Veteran
Posts: 450
From: Oklahoma



I have tried but

Just to say select * from ColorTBL and have it display what would I need to do


Dim stDocName As String
Dim WorkBase As Database
Dim WorkRS1 As Recordset
Dim sSQL As String

Set WorkBase = CurrentDb

sSQL = “Select * from ColorTBL”

Set WorkRS1 = WorkBase.OpenRecordset(sSQL)
WorkRS1 = WorkBase.Execute(sSQL)



*****************

thanks
steve
Go to the top of the page
 
+
R. Hicks
post Nov 4 2008, 05:38 PM
Post #11

UA Forum Administrator
Posts: 38,073
From: Birmingham, Alabama USA



You can not use the Execute method to open a Select Query ...
It only works with Action queries such as Update and Append queries ....

What is the query to be use for ???
The answer to this may help with a possible soultion ...

RDH
Go to the top of the page
 
+
CHKarcher
post Nov 4 2008, 05:44 PM
Post #12

UtterAccess Veteran
Posts: 450
From: Oklahoma



I have a form that I want to have the user enter in a number of invoice number seperated by commas, then have then click a button to open a query.

I can build the query except when I put the IN statement in the criteria (looking at the form textbox - it does not work when there is more than one value in the textbox.

thanks for the assistance
steve.
Go to the top of the page
 
+
R. Hicks
post Nov 4 2008, 06:10 PM
Post #13

UA Forum Administrator
Posts: 38,073
From: Birmingham, Alabama USA



Why don't you display query results in a form ????
You could then create the SQL as you are attempting to do and assign it to the form's recordsource when the form is being opened.

RDH
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 08:50 AM