Results 1 to 5 of 5

Thread: Search Function

  1. #1
    Join Date
    Jul 2009
    Posts
    5

    Unanswered: Search Function

    I have a search script, as shown below.
    It searches by a number called "Global#". The problem is that by boss updates the records for the Global#, but doesn't want the changes saved in the same record. So I use a clone script to create multiple records with the same Global#.

    The problem I run into is when a search is made by a user, I need the most recently added record for the Global# to show up. I have a date stamp field on all the records called "DateAdded". Is there a way I could modify the script below to have the search bring up the most recently added record for the specified Global#.

    Any help would be greatly appreciated.
    Thanks
    John

    Code:
    <SCRIPT language=vbscript for=Search event=onclick>
    <!--
    <!--
    ' Clone the recordset.
    Dim rs
    Set rs = MSODSC.DataPages(0).Recordset.Clone
    On error resume next
    
    rs.find "Global#=" & CStr(inputbox("Enter a Global#","Find"))
    
    ' Custom error handling.
    If (err.number <> 0) Then
        Msgbox "Error: " & err.number & " " & err.description,,"Invalid Search"
        Exit Sub
    End If
    ' Check search results for success.
    If (rs.bof) or (rs.eof) Then
        Msgbox "No Product found",,"Search Done"
        Exit Sub
    End If
    MSODSC.DataPages(0).Recordset.Bookmark = rs.Bookmark
    -->
    
    -->
    </SCRIPT>
    Last edited by jmac1983; 07-28-09 at 10:47.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    on your select set a sort order and a top predicate

    eg
    select top 1 my,column,list from mytable order by dateadded DESC
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jul 2009
    Posts
    5
    Quote Originally Posted by healdem
    on your select set a sort order and a top predicate

    eg
    select top 1 my,column,list from mytable order by dateadded DESC
    Thank you for the help. I'm sorry I'm a little limited with my knowledge with this type of programming. My background is in html, php, javascript and a few others.

    What I've created so far with the search function I've followed tutorials from Microsoft. So I have no idea how to go about doing what you've suggested.

    If there is any other direction you can give me, or suggestions on where I can learn more please let me know.

    Thanks
    John
    Last edited by jmac1983; 07-28-09 at 11:52.

  4. #4
    Join Date
    Jul 2009
    Posts
    5
    Quote Originally Posted by healdem
    on your select set a sort order and a top predicate

    eg
    select top 1 my,column,list from mytable order by dateadded DESC
    Okay so here is what I've come up with trying to work from the above.
    Code:
    
    strMDB = "select top1 Global# from Corrugated_Specifications order by DateAdded DESC"
    "Corrugated_Specifications" is the name of the table, and "Global#" is the column I want to search from. Ordered by "DateAdded" descending.

    This is for a data access page if that makes any difference.
    Now could some help with where I put this into my script?

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    is this Access or ASP?
    its certainly not what I recognise as Access VBA

    you need to open a recordsource

    so im guessing..
    rs.open (mySQL)
    assuming that mySQL is your SQL string.
    generally its better to allocdate the SQL to a string variable before sending the SQL to be parsed. this way its easier to debug.
    if you are anal or at all concerned about app performance or memory usage, having once proved the SQL is 'right' then by all means move the SQL straight into the rs.open method call
    Set rs = MSODSC.DataPages(0).Recordset.Clone
    needs changing to open a recordsource
    its probably going to be
    set rs
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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