My Assistant
![]() ![]() |
|
|
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 |
|
|
|
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 |
|
|
|
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 |
|
|
|
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 |
|
|
|
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 |
|
|
|
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 |
|
|
|
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 |
|
|
|
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 |
|
|
|
Nov 4 2008, 04:36 PM
Post
#9
|
|
|
UA Forum Administrator Posts: 38,073 From: Birmingham, Alabama USA |
Yes .. that should work ..
RDH |
|
|
|
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 |
|
|
|
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 |
|
|
|
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. |
|
|
|
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 Top · Lo-Fi Version | Time is now: 22nd May 2013 - 08:50 AM |