Can you grab max() from access db?

Results 1 to 3 of 3

Thread: Can you grab max() from access db?

  1. #1
    Knyte Guest

    Default Can you grab max() from access db?

    I am trying to get the max value from a field and this is the error message I get...&#039<BR>ADODB.Fields error &#039 800a0cc1&#039 <BR><BR>ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application&#039<BR><BR>This is the code....<BR>Dim sRandomNum,query,connect,varRec,d<BR>set connect=server.createobject("ADODB.Connection")<BR > "TestClrTest"<BR>set varRec=server.createobject("ADODB.Recordset")<BR>q uery="SELECT Max(tbl_Address.OBJID) FROM tbl_Address"<BR> query,connect<BR><BR>d=varRec.Fields("OBJID")<BR>% &#062;<BR>Your random number is as follows:<BR><BR>&#060;%=d%&#062;<BR><BR>Is there something I&#039m doing wrong or is there a different way to do this?<BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default Naming (or lack of) problem

    When you do:<BR><BR>query="SELECT Max(tbl_Address.OBJID) FROM tbl_Address"<BR> query,connect<BR><BR>SQL does *NOT* give use OBJID as the name of the field that receives that MAX value. In fact, SQL doesn&#039t assign *any* name, by default.<BR><BR>So two solutions:<BR><BR>(1) d = varRec.Fields(0).value<BR><BR>or<BR><BR>(2) query="SELECT Max(tbl_Address.OBJID) AS IDmax FROM tbl_Address"<BR>&nbsp;&nbsp;&nbsp;&nbsp;d = varRec.Fields("IDmax").value

  3. #3
    Knyte Guest

    Default Thanks.

    This was perfect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts