Searching on a highlighted word in a form

igillesp

Registered User.
Local time
Today, 00:02
Joined
Feb 27, 2008
Messages
20
Hi!

First post...

I have a MS Access 2003 form for classifying various drugs that patients take. Several drug names are written in the same field and users can currently look up a description of any one drug by highlighting the word, copying it to the clipboard and then clicking a button which opens a subform to process the information using:

Code:
    Dim MyDataObj As New DataObject
    MyDataObj.GetFromClipboard
    GetOffClipboard = MyDataObj.GetText()
    
    Dim MyVar As Variant
    MyVar = MyDataObj.GetText

    Me.Drug.SetFocus
    DoCmd.FindRecord MyVar

This works weel, but I'd like the user to skip the 'copy to clipboard' stage, in that they would simply double-click the word to highlight and then click the search button. However, I cant find any code on whether this is possible.

Any ideas?

Thanks!
 
Have them highlight the word, and then in double-click event (called DblClick in code), perform the copy to the clipboard (a SendKeys "^C" will do that) and then your code.
 
i find the following useful - it doesnt take up too much screen real estate

provide a text box for the searchstring (slightly different to yuor idea) - instead of using the clipboard, the user enters whatever text he is interested in, and then clicks a command button which places your cursor in the required field (setfocus method) you wish to search and then search with the following code

the first version finds the FIRST occurrence of the searchstring in the targetfield, and repositions the form to that record

the second version searches down to find the NEXT occurrence

its equivalent, but easier than clicking the binoculars, especially for non technical users

i normally provide a findfirst and findnext button next to the searchstring textbox.

Code:
sub findfirst
    targetfield.SetFocus
    DoCmd.FindRecord searchstring, acAnywhere, False, acSearchAll, False, acCurrent, True
end sub
    
sub findnext
    targetfield.SetFocus
    DoCmd.FindRecord searchstring, acAnywhere, False, acDown, False, acCurrent, false
end sub
 

Users who are viewing this thread

Back
Top Bottom