This topic is locked

Dropdown list of numbers... plus 1

9/15/2009 1:42:11 PM
ASPRunnerPro General questions
T
Tim author

I have a field called priority, which is data type int. I'd like to read all current priority fields from the table and then add the next sequential number, then make this list available as a dropdown list on the Add and Edit forms. Is this possible, and if so, how would I do it?
Thanks,

Tim

J
Jane 9/16/2009

Tim,
you can create new table for these values and use this table as lookup table, then find max priority value in the Add page: Before process event and add new record to the lookup table if needed.

T
Tim author 9/16/2009

Thanks Jane. I was hoping there was some fancy code I could add that would simply add the next number to the dropdown list (or create the entire list of numbers) at run time, but if not, this other table approach will work just fine.
Thanks for your help,

Tim

C
clig 9/16/2009



I have a field called priority, which is data type int. I'd like to read all current priority fields from the table and then add the next sequential number, then make this list available as a dropdown list on the Add and Edit forms. Is this possible, and if so, how would I do it?
Thanks,

Tim


you could create a view

SELECT MAX(priority) + 1 AS priority FROM priority_table

  • call this view in the onload or beforeprocess event assign it to a session var then assign that session var as the default value of that field then you do not need a dropdown list...
    Sub BeforeProcessList(dbConnection)

    strSQLExists = "SELECT MAX(priority) + 1 AS priority FROM priority_table"

    set rsExists = CreateObject("ADODB.Recordset")

    rsExists.Open strSQLExists, dbConnection
    if not rsExists.eof then

    SESSION("priority") = rsExists("priority")
    else
    end if

    rsExists.Close : set rsExists = Nothing
    End Sub ' BeforeProcessList
  • and/or write the value directly to your table "before edit"

T
Tim author 9/22/2009

Hey, thanks clig. Actually, I am doing that already, but I want the user to be able to choose the next priority OR a previously used one, thereby inserting into the list of existing priorities. I would then adjust the other ones accordingly. I have accomplished this with the priorty table, as Jane suggested, and I just add the next possible priority (with max + 1 code very similar to yours) to the table on load of the Add page. This works ok, it just requires some maintenance code.
Thanks again for your thoughts though.

Tim