Solved

Lookup table and find record (between)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

758 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

17 Experts available now in Live!

Get 1:1 Help Now