Connecting Tech Pros Worldwide Help | Site Map

Search for record between two fields (Access)

  #1  
Old September 5th, 2008, 03:15 PM
David
Guest
 
Posts: n/a
Hi,

I have a table called 'jobserial'

This contains amongst others, 2 fields called 'PSL_F_Serial' &
'PSL_L_Serial'
Both of these are 'Text' fields (VarChar) which at present hold serial
numbers

I have a form on my ASP page which loads the new serials into the
Access database as a range only, i.e. The first serial in the range
(from TEXTBOX1) loads into 'PSL_F_Serial' and the last serial in the
range (from TEXTBOX2) loads into 'PSL_L_Serial'
Only these 2 numbers are stored per record in the table.

I need an SQL statement that will check the 2 serial numbers entered
against matching serials in 'PSL_F_Serial' & 'PSL_L_Serial' and also
BETWEEN 'PSL_F_Serial' & 'PSL_L_Serial'.

i.e. if record 52 exists as :

PSL_F_Serial = 0908216206
and
PSL_L_Serial = 0908216245

so, in theory, there are 40 serial numbers including the first & last
in this range, but only the first & last are stored.

Then when the user enters a number in Textbox 1 and 2 it needs to find
out if

Text box1 = 0908216206 or 0908216245....RECORD FOUND
Text box2 = 0908216206 or 0908216245....RECORD FOUND
and
If user enters any number BETWEEN 0908216206 & 0908216245 in textbox1
or 2 ..... RECORD FOUND

Could you show me how ? thanks .... this one is really important, as
at present, duplicates are getting into the DB if the number entered
is BETWEEN the range, as I have not worked out how to catch them !

Many thanks in advance

David
  #2  
Old September 5th, 2008, 09:45 PM
Ron Hinds
Guest
 
Posts: n/a

re: Search for record between two fields (Access)



"David" <davidgordon@scene-double.co.ukwrote in message
news:e5b52c3a-76ee-442a-a789-3e6597b34762@f36g2000hsa.googlegroups.com...
Quote:
Hi,
>
I have a table called 'jobserial'
>
This contains amongst others, 2 fields called 'PSL_F_Serial' &
'PSL_L_Serial'
Both of these are 'Text' fields (VarChar) which at present hold serial
numbers
>
I have a form on my ASP page which loads the new serials into the
Access database as a range only, i.e. The first serial in the range
(from TEXTBOX1) loads into 'PSL_F_Serial' and the last serial in the
range (from TEXTBOX2) loads into 'PSL_L_Serial'
Only these 2 numbers are stored per record in the table.
>
I need an SQL statement that will check the 2 serial numbers entered
against matching serials in 'PSL_F_Serial' & 'PSL_L_Serial' and also
BETWEEN 'PSL_F_Serial' & 'PSL_L_Serial'.
>
i.e. if record 52 exists as :
>
PSL_F_Serial = 0908216206
and
PSL_L_Serial = 0908216245
>
so, in theory, there are 40 serial numbers including the first & last
in this range, but only the first & last are stored.
>
Then when the user enters a number in Textbox 1 and 2 it needs to find
out if
>
Text box1 = 0908216206 or 0908216245....RECORD FOUND
Text box2 = 0908216206 or 0908216245....RECORD FOUND
and
If user enters any number BETWEEN 0908216206 & 0908216245 in textbox1
or 2 ..... RECORD FOUND
>
Could you show me how ? thanks .... this one is really important, as
at present, duplicates are getting into the DB if the number entered
is BETWEEN the range, as I have not worked out how to catch them !
>
Many thanks in advance
>
David
If you really mean OR here:
Quote:
If user enters any number BETWEEN 0908216206 & 0908216245 in textbox1
or 2 ..... RECORD FOUND
use the statement below as-is. But I think what you really want is AND; if
so, just change the OR below to AND. The rest is assuming you already know
how to open a connection and a recrodset...

strSQL = "SELECT PSL_F_Serial, PSL_L_Serial FROM jobserial WHERE ('" &
TextBox1 & "'>=PSL_F_Serial AND '" & TextBox1 & "<>=PSL_L_Serial) OR ('" &
TextBox2 & "'>=PSL_F_Serial AND '" & TextBox2 & "<>=PSL_L_Serial)

rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic

If rs.EOF Then
'Record not found
Else
'Record found
End If


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access 2002 vs. 2003 Neil answers 52 February 16th, 2006 10:35 PM
UI Metaphors for complex criteria selection Steve Jorgensen answers 8 November 13th, 2005 03:05 PM
Advice needed: Should we upgrade MS Access 2000? And if so to what? ship answers 47 November 13th, 2005 11:39 AM
Creating a record in a child table using ADO Ilan Sebba answers 5 November 12th, 2005 03:55 PM