It is a VERY Good idea on your part to move this in to some type of table.
having to modify code for cases which can be listed
in a table is problematic it as you have to modify all the time as you
mention.
> hello to all
> Some of my procedures have code like this:
[quoted text clipped - 9 lines]
> ....
> End Select
Just build a table:
eg:
CaseN Marker
1 8.3
1 12.7
1 15.4
2 14.7
2 17.1
etc. etc.
Now, to get a value, you go:
Dim strSql As String
Dim strMarker As String
Dim strCaseN As String
Dim strResult As String
strCaseN = 1
strMarker = 12
strSql = " SELECT TOP 1 Marker FROM tblMarkerValues" & _
" where CaseN = " & strCaseN & " and Marker <= " & strMarker & _
" ORDER BY Marker DESC"
strResult = CurrentDb.OpenRecordset(strSql)(0)
Debug.Print strResult
The above stir result will have the next lowest value, in teh above example,
we would get 8.3...
> In my code, n runs from case 1 to case 7, and each of these values has 3
> Marker cases.
It not clear "what" you do inside of each "case" in the code..but, it sounds
like some general function could be feed values from a table...
> Question 2: There are a few places where I use a combobox showing the
> values of n as a list, say 1 to 7. Again, I have to recode these each
> year.
> How can I make the combobox show whatever distinct values of n are in the
> table above?
I don't really think of a "set of two values" As duplicated values.
However, just build a query and use Group by, or distinct ......
eg:
select distinct CaseN from tblMarkerValues

Signature
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
Dale Fye - 11 Jan 2008 13:45 GMT
You don't really indicate what you are doing inside the case statement. I
agree with Albert that you ought to move these criteria into a table.
Structure might look like:
YearField NValue Marker SomeValue SomeEqn
2007 1 8.3
2007 1 12.7
2007 1 15.4
2007 2 14.7
2007 2 17.1
I would use a SomeValue field if the values of N and Marker should return a
single value. You could use SomeEqn to store an equation that would be
evaluated in the given situation.
The challenge here is deciding what to do when you've found a criteria that
works.
I like Albert's idea of using SQL to identify your recordsets, but you have
to be careful of the order that you loop through the recordsets. If the
values of N and Marker are in a data table, and you want to compare them to
these values in this new table, you will need to make sure you limit your
result set so that you don't perform the same action on the same record
multiple times. One way to do this might be to create a recordset:
Dim rs as DAO.Recordset
Dim strSQL as string
strSQL = "SELECT NValue, Marker FROM yourTable " _
& " WHERE [YearField] = 2007 " _
& " ORDER BY NValue ASC, Marker DESC"
set rs = currentdb.OpenRecordset
Do While not rs.eof
if x = nValue AND y > Marker Then
'do something
Exit Do
endif
rs.movenext
Loop
Without more information on what you are doing inside the Select Case
statements, or how this code is being used (is it in a forms event), I cannot
provide any more recommendations.
HTH
Dale

Signature
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
> It is a VERY Good idea on your part to move this in to some type of table.
> having to modify code for cases which can be listed
[quoted text clipped - 68 lines]
>
> select distinct CaseN from tblMarkerValues
Albert D. Kallal - 11 Jan 2008 18:42 GMT
> strSQL = "SELECT NValue, Marker FROM yourTable " _
> & " WHERE [YearField] = 2007 " _
[quoted text clipped - 7 lines]
> rs.movenext
> Loop
You do realize my sql statement does replace the above loop???
Just use:
strSql = " SELECT TOP 1 Marker FROM tblMarkerValues" & _
" where CaseN = " & strCaseN & " and Marker <= " & strMarker & _
" ORDER BY Marker DESC"
strResult = CurrentDb.OpenRecordset(strSql)(0)
the above will find the "first" value <= strMarker..and restriced to
CaseN...
There not a need for a loop here.....

Signature
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
Dale Fye - 11 Jan 2008 19:25 GMT
Albert,
Actually, I misread your SQL the first time through, but my point remains
the same. Without knowing how the OP is using the current Case statement, it
is difficult to determine what to do with the information once you get it.
Unless you can code some actions (SQL action strings, macros, strings that
can be processed using Eval( ) ) into this new table, the poster is still
going to have to have specialized code that does something based on the value
of n and Marker, and I'm not sure how putting the values in a table fix that.
Maybe the approach is to write a custom function or subroutine that you pass
the values of N and Marker to. Then all you would have to edit is the
function.
Dale

Signature
Don''t forget to rate the post if it was helpful!
email address is invalid
Please reply to newsgroup only.
> > strSQL = "SELECT NValue, Marker FROM yourTable " _
> > & " WHERE [YearField] = 2007 " _
[quoted text clipped - 22 lines]
>
> There not a need for a loop here.....