Solved

Lookup table and find record (between)

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

808 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