Solved

Lookup table and find record (between)

Posted on 2014-07-20
3
292 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 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