Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:55:36+00:00 2026-06-07T09:55:36+00:00

I have a question for which I found a rather long solution of which

  • 0

I have a question for which I found a rather long solution of which I don’t think that it is good practise.
However I feel there must be a syntax available that is able to solve this issue right away without too many complexities.
I bumped into this problem a few times already, and I’d like to know for once and for all.

I have a table called “T_STOP_LOSS”, in which I have three columns “LIVES_FROM”, “LIVES_TO” and “SL_VALUE” (All number types + the column containing ID with AutoNumber type).
I want to retrieve the record containing the SL_VALUE where a variable value lies in the interval between LIVES_FROM and LIVES_TO.

ID  LIVES_FROM   LIVES_TO   NR_COUNTRIES_FROM   NR_COUNTRIES_TO SL_VALUE
1   0   999 2   2   39,3
12  0   999 3   3   34,6
23  0   999 4   4   29,6
34  0   999 5   9   25,7
45  0   999 10  100 22,17
46  1000    1499    2   2   31,1
2   1000    1499    3   3   27,4
13  1000    1499    4   4   23,3
24  1000    1499    5   9   20,4
35  1000    1499    10  100 17,5
36  1500    1999    2   2   23,6
47  1500    1999    3   3   20,7
3   1500    1999    4   4   17,7
14  1500    1999    5   9   15,4
25  1500    1999    10  100 13,3
26  2000    2999    2   2   23,6
37  2000    2999    3   3   20,7
48  2000    2999    4   4   17,7
4   2000    2999    5   9   15,4
15  2000    2999    10  100 13,3

Normally I would use:

lNr_Lives = <Something> '(Retrieved via Textbox)
sSQL_Select = "SELECT SLVALUE FROM T_STOP_LOSS WHERE LIVES_FROM <= " & LNr_Lives & " AND LIVES_TO >= " & LNr_Lives & ";"

However, LIVES_FROM and LIVES_TO are related to the table NR_LIVES through a foreign key.
The above statement will never work because table ‘NR_LIVES’ contains an ID field as Primary Key, which is used to link to the T_STOP_LOSS table.
(The columns in NR_LIVES are named: ID, NR_LIVES_FROM and NR_LIVES_TO (not that it matters)).

ID  NR_LIVES_FROM   NR_LIVES_TO
1   0   999
2   1000    1499
3   1500    1999
4   2000    2999

Please tell me, what would you consider to be the briefest way to access the real value of LIVES_FROM and LIVES_TO that is stored in the NR_LIVES table and get my SELECT statement working the way I expect it (Return the record that contains the SL for the right interval).

I hope that my question is clear. If not, don’t hesitate to mention.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:55:37+00:00Added an answer on June 7, 2026 at 9:55 am

    Thanks to Nicolas, I found what I needed.

    Dim cQueries                    As clsQueries
    Dim oRst                        As DAO.Recordset
    Dim sSQL_Select                 As String
    Dim LNr_Lives                   As Long
    Dim iNr_Countries               As Integer
    Dim i As Integer
    
    
    If Not IsNull(Me.txt_Nr_Lives) Then
        LNr_Lives = Me.txt_Nr_Lives
    Else
        MsgBox "No number of lives defined!", vbCritical
        Exit Sub
    End If
    
    If Not IsNull(Me.cbb_Nr_Countries) Then
        iNr_Countries = Me.cbb_Nr_Countries
    Else
        MsgBox "No number of countries defined!", vbCritical
        Exit Sub
    End If
    
    Set cQueries = New clsQueries
    sSQL_Select = "SELECT " & _
                        "* " & _
                    "FROM " & _
                        "T_STOP_LOSS " & _
                    "INNER JOIN " & _
                        "NR_LIVES ON (T_STOP_LOSS.LIVES_FROM = NR_LIVES.ID) " & _
                    " WHERE " & _
                        "NR_LIVES.NR_LIVES_FROM <= " & LNr_Lives & _
                    " AND " & _
                        "NR_LIVES.NR_LIVES_TO >= " & LNr_Lives & _
                    " AND " & _
                        "T_STOP_LOSS.NR_COUNTRIES_FROM <= " & iNr_Countries & _
                    " AND " & _
                        "T_STOP_LOSS.NR_COUNTRIES_TO >= " & iNr_Countries & ";"
    
    Set oRst = cQueries.Select_Statement(sSQL_Select)
    oRst.MoveFirst
    
    Do While Not oRst.EOF
        Me.txt_FSL = oRst![SL_VALUE]
        oRst.MoveNext
    Loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question to which I have not found an answer. Let's say
I have a question which I think involves conditional entropy in the field of
I have found several questions asking about template typedefs in C++0x, which are resolved
I have a question which I am sure is simple but I have slight
I have a question which is slightly similar to this question on stackoverflow std::cin.clear()
I have a question which is described below: What problems would arise for testing
I have a question which may be somewhat silly because I'm pretty sure I
I have a question which involves calling a function with 2 parameters of a
Hey guys i have a question which i have been looking for the answer
this is my first time posting here, I have a question which I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.