Solved

Lookup table and find record (between)

Posted on 2014-07-20
3
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

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

Back Up Your Microsoft Windows Server®

Back up 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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

717 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