Recordselection by Query (1 Viewer)

mhjhermans

New member
Local time
Today, 23:54
Joined
Sep 15, 2011
Messages
5
I have for example a table with; a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z.
Now I have a form with 2 textboxes. Textbox one is the input of the start of my selectionrange, for example "f".
Textbox two I want to tell the query how many records I want to see after the input in textbox one. For example "6".
The result should be g,h,i,j,k,l.
HOW CAN I MAKE THIS WORK?
 

vbaInet

AWF VIP
Local time
Today, 22:54
Joined
Jan 22, 2010
Messages
26,374
All air code to be used in a function -->
Code:
dim strAlphas(1 to 26) as string, strConcats as string, strSQL as string

redim strAlphas = ("a","b","c","d"... ) --> include the other alphabets

if Me.txtStart = 0 or intEnd > intStart or  then
    exit function
end if

For Me.txtStart to Me.txtEnd
    strConcats = strConcats & strAlphas(Me.txtStart) & ", "
Next

strConcats = Left(strConcats, Len(strConcats) - 2)

strSQL = "SELECT * FROM TableName WHERE SomeField IN (" & strConcats & ");"

...do something with strSQL here.
Perform some more checks to ensure that a numeric value is entered in both textboxes too.
 

mhjhermans

New member
Local time
Today, 23:54
Joined
Sep 15, 2011
Messages
5
Thanks for your fast reply, but the range of a untill z is just an example. In fact I have to make an selection of records in a table of about 3000 unique numbers. So one of these numbers is my parameter in textbox 1 and then the selection should be the amount of the value in textbox 2.
I'm sorry if I explained the problem not good enough.
 

vbaInet

AWF VIP
Local time
Today, 22:54
Joined
Jan 22, 2010
Messages
26,374
Give some real examples in this format:

1. Here are a set of records (i.e. about 5 records should be sufficient - attached or written within code tags)
2. Here's what text box 1 and textbox 2 contain
3. Here are the set of records I expect to see
 

mhjhermans

New member
Local time
Today, 23:54
Joined
Sep 15, 2011
Messages
5
Give some real examples in this format:

1. Here are a set of records (i.e. about 5 records should be sufficient - attached or written within code tags)
2. Here's what text box 1 and textbox 2 contain
3. Here are the set of records I expect to see


Like this

partnumber
1236548
5263254
5448712
5547789
2525254
4488756
6558744

Textbox 1 = 5448712
Textbox 2 = 3

Result;

5547789
2525254
4488756
 

vbaInet

AWF VIP
Local time
Today, 22:54
Joined
Jan 22, 2010
Messages
26,374
So what you really want is the TOP predicate:
Code:
strSQL = "SELECT TOP " & Me.Textbox2 & " TableName.* FROM TableName WHERE partnumber = " & Me.Textbox1 & ");"

...do something with strSQL here.
However, this will be a meaningless exercise if there's no sorting in place.
 

mhjhermans

New member
Local time
Today, 23:54
Joined
Sep 15, 2011
Messages
5
So what you really want is the TOP predicate:
Code:
strSQL = "SELECT TOP " & Me.Textbox2 & " TableName.* FROM TableName WHERE partnumber = " & Me.Textbox1 & ");"
 
...do something with strSQL here.
However, this will be a meaningless exercise if there's no sorting in place.


I thought it was not easy. I thought there would be a simple solution for my problem.
Thanks anyway...
 

Users who are viewing this thread

Top Bottom