Solved

Lookup table and find record (between)

Posted on 2014-07-20
3
291 Views
Last Modified: 2014-07-29
See table Uniq_Serials_Edited.

Note the fields "StartSerial" and "EndSerial",

Example: I have a form. If my users key in "00019" then I want to display the record where the "StartSerial" is "00019" and the "EndSerial" is "00208".

Similarly, user keys "00770" should display record where "StartSerial" is "00767" and "EndSerial" is "00777".

For sake of example, let's display field "Exterior Finish".

How do I do this "between" functionality?
SerialsYuri-edited.accdb
0
Comment
Question by:Patrick O'Dea
3 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 40207163
on my ipad, so cannot look at your database, but here is how I would do it.

This assumes that you want to do this in the AfterUpdate event of a textbox called txt_Serial, and that these serial numbers are numeric, not strings.

Private Sub txt_Serial_AfterUpdate

    Dim strCriteria as string

    strCriteria = "[StartSerial] <= " & me.txt_Serial & " AND [EndSerial] > " & me.txt_Serial
    With me.recordsetclone
        .findfirst strcriteria
        if .nomatch then
            msgbox "no record found for this serial #"
        Else
            me.bookmark = .bookmark
        endif
    end with

End Sub

Open in new window

You may want to change the > to >= in the criteria string, but I got the impression you wanted to test [StartSerial] <= me.txt_Serial < [EndSerial].  You could also use:

strCriteria = me.txt_Serial & " BETWEEN [StartSerial] AND [EndSerial]"

but I prefer to use the explicit syntax, so I know exactly what I am getting.

Now, the challenge with this is what if you enter a serial # lower than the lowest # in the [StartSerial] field of your table, or greater than the greatest [EndSerial] in your your table.  What do you want to do then?
0
 
LVL 30

Expert Comment

by:hnasr
ID: 40207985
Try to compact and repair the database and upload. You may want to exclude objects not related to the current issue.
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 40228235
POints awarded.
(I ended up abandoning my question and doing things a different way!)

Thanks for help (again) !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now