For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > February 2005 > SQL Find help needed









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SQL Find help needed
Atreju

2005-02-25, 8:55 pm

I use a Find to get to a record matching criteria.
However, if it cant find, it just goes to the last record.
I'd like to be able to programmatically tell if it found, if not, to
return to bookmark, not end up on last record.


---Atreju---
Gavin

2005-02-25, 8:55 pm

I would use something like:



sql = "SELECT * FROM database WHERE ID LIKE '%test search%'"
rs.open sql

if rs.eof = true then 'No records found
'Do some code to point to your bookmarked record
end if


Gavin


"Atreju" <someone@who.hates.junkmail> wrote in message
news:99vu11pegu8fc69q4mpr7squ811ge94lek@
4ax.com...
> I use a Find to get to a record matching criteria.
> However, if it cant find, it just goes to the last record.
> I'd like to be able to programmatically tell if it found, if not, to
> return to bookmark, not end up on last record.
>
>
> ---Atreju---



Jeff Johnson [MVP: VB]

2005-02-25, 8:55 pm


"Atreju" <someone@who.hates.junkmail> wrote in message
news:99vu11pegu8fc69q4mpr7squ811ge94lek@
4ax.com...

>I use a Find to get to a record matching criteria.
> However, if it cant find, it just goes to the last record.
> I'd like to be able to programmatically tell if it found, if not, to
> return to bookmark, not end up on last record.


ADO? DAO?


Saga

2005-02-25, 8:55 pm


If using ADO, then maybe something like this:

dim varBk as variant

'Save the bookmark
varBK = rs.Bookmark

'Search for it
rs.find "xyz=1234", 0, adSearchForward

if not rs.eof then
'Found do whatever...
else
'Not found, return to bookmark.
rs.Bookmark = varBK
end if

Good luck!
Saga


"Atreju" <someone@who.hates.junkmail> wrote in message
news:99vu11pegu8fc69q4mpr7squ811ge94lek@
4ax.com...
>I use a Find to get to a record matching criteria.
> However, if it cant find, it just goes to the last record.
> I'd like to be able to programmatically tell if it found, if not, to
> return to bookmark, not end up on last record.
>
>
> ---Atreju---



Saga

2005-02-25, 8:55 pm


> rs.find "xyz=1234", 0, adSearchForward


This searches fron the current positionin rs, if you want to search
the entire rs, then do this:

rs.find "xyz=1234", 0, adSearchForward, adBookmarkFirst


"Saga" <antiSpam@somewhere.com> wrote in message
news:eRTJUC4GFHA.2452@TK2MSFTNGP10.phx.gbl...
>
> If using ADO, then maybe something like this:
>
> dim varBk as variant
>
> 'Save the bookmark
> varBK = rs.Bookmark
>
> 'Search for it
> rs.find "xyz=1234", 0, adSearchForward
>
> if not rs.eof then
> 'Found do whatever...
> else
> 'Not found, return to bookmark.
> rs.Bookmark = varBK
> end if
>
> Good luck!
> Saga
>
>
> "Atreju" <someone@who.hates.junkmail> wrote in message
> news:99vu11pegu8fc69q4mpr7squ811ge94lek@
4ax.com...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com