=?Utf-8?B?SWFuIG9uIENvd2Fu?= <IanonCowan@discussions.microsoft.com>
wrote in news:63F94C01-F2FF-44C4-B67F-74FD0448C0AE@microsoft.com:
> Problem: A Word doc contains words (usually in a footnote, but doesn't
> have to be), which are keys to records in an Access database. How can
> these Access records be displayed when the Word items are clicked, or
> selected and clicked?
I don't think that Word has a MouseClick event... you could use the
Selection object and a ctrl-key or toolbar button to call the code. This
is very obviously air code. You'd be better off asking this in a Word
programming group.
public sub LookItUp
dim dbe as DBEngine ' needs reference to DAO.
dim db as database ' ditto
dim jetSQL as string
dim rs as Recordset
dim rng as range
' get the user selection
set rng = activewindow.selection.range
' bug out if it's not exactly one word
if rng.words.count <> 1 Then exit sub
' get the database
set dbe=new DBEngine
set db = dbe.OpenDatabase(pathToMyDatabase, false, true)
' look up the word
jetSQL = "SELECT Something FROM MyTable " & _
"WHERE TheWord = """ & rng.Text & """;"
set rst=db.OpenRecordset(jetSQL, dbOpenSnapshot, dbForwardOnly)
' respond to the user
if rst.EOF then
msgbox "Sorry, can't find that word"
else
msgbox "That word returned: """ & rst!Something & """"
End if
' clean up database objects
rst.Close
db.Close
End Sub
... or something like that. Hope it helps
Tim F
Ian on Cowan - 26 Sep 2006 19:56 GMT
Many thanks Tim, there's definitely something to try there!
> =?Utf-8?B?SWFuIG9uIENvd2Fu?= <IanonCowan@discussions.microsoft.com>
> wrote in news:63F94C01-F2FF-44C4-B67F-74FD0448C0AE@microsoft.com:
[quoted text clipped - 50 lines]
>
> Tim F