473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

VBA code for searching for a keyword and re-directing to the specific page?

Hi all,

First, Happy New Year to all :)

I am stuck with this problem for my project so I am writing to seek some help regarding this matter.

Basically, I am having a form with a search function. Each field of the record returned from the search (using keyword) will be displayed, including an attachment field (hyperlink data type). I want it to work in a way that every time a user double-click on the hyperlink to open the attachment, the same search keyword used above will be used to search inside the attachment, and point directly to that specific page containing the keyword instead of the first page as usual.

I have been able to store and open the attachment so I need help with the searching and page-pointing part.

I look forward to getting any inputs from you. Any help is greatly appreciated. Thank you so much.
Jan 3 '12 #1
8 3018
Mihail
759 512MB
Just an idea:

Say that you open the attachment using Excel.
Doing that you lose control from the Access application.
So you need to manage the search task from Excel.

In order to do that you must save (from Access) somewhere the keyword (maybe in a new file, or table or even in clipboard), then open the attachment, then instruct Excel to read the keyword and perform the task).

I say Excel as an example but can be any other application if you know how to develop programs for that application.

Good luck !
Jan 3 '12 #2
Thanks Mihail,

My idea was to search for the keyword inside the document to get the particular page number, and then open the hyperlink with pointing to that particular page mentioned above.

Putting aside the part of searching first, can anyone please help me with the code for moving to a specific page in a WORD document upon opening ? I am new to VBA so still struggle to get this done.

Thanks a lot

Currently I use this code for opening the hyperlink

Expand|Select|Wrap|Line Numbers
  1. Function GetUserAddress() As Boolean
  2.     Dim strInput As String
  3.  
  4.     On Error GoTo Error_GetUserAddress
  5.     strInput = InputBox("Enter a valid address")
  6.     'In fact the address will be passed from another form. This is just for testing purpose only
  7.     Application.FollowHyperlink strInput, , True
  8.     GetUserAddress = True
  9.  
  10. Exit_GetUserAddress:
  11.     Exit Function
  12.  
  13. Error_GetUserAddress:
  14.     MsgBox Err & ": " & Err.Description
  15.     GetUserAddress = False
  16.     Resume Exit_GetUserAddress
  17. End Function
  18.  
  19. Private Sub Cmd_Click()
  20. If GetUserAddress = True Then
  21.         MsgBox "Successfully followed hyperlink."
  22.     Else
  23.         MsgBox "Could not follow hyperlink."
  24.     End If
  25.  
  26. End Sub
Jan 4 '12 #3
Mihail
759 512MB
This macro do the job (Word 2007)
Expand|Select|Wrap|Line Numbers
  1. Sub Macro1()
  2.     Selection.HomeKey Unit:=wdStory
  3.  
  4. Dim PageNumber As Long, i As Long
  5.     PageNumber = InputBox("Page number ?")
  6.     i = 1
  7.     For i = 1 To PageNumber - 1
  8.         Application.Browser.Next
  9.     Next i
  10. End Sub
Jan 4 '12 #4
Thanks so much for your prompt response Mihail. Works like charms.

Hope you don't mind if I ask you one more thing:

I have managed to do the Find function using Macro in the Word document. The only thing that is left with is passing the keyword from Access to the Word document. The path of the document is stored as hyperlink in Access, which opens upon user clicking it. Is there a way to pass the parameter from Access to Word similar to that between forms in Access ?

Once again, thank you so much for your help. I really appreciate that.

-D
Jan 5 '12 #5
Mihail
759 512MB
From Access put the keyword in the clippboard.
In Word I think that must exist an OPEN event for documents. So use this event to store data from clippboard into a variable.
Sorry but I never do a program for Word so I can't say "how to".

Another approach is to write the keyword into a file (from Access) then read it from Word and use it.
I think I can help you to do this if you can not do yourself. Let me know.
Jan 5 '12 #6
Hi Mihail,

Thanks for your input. I will try it out and get back to you asap.

-D
Jan 6 '12 #7
I have found a way to do this. Turned out to be quite simple:

Expand|Select|Wrap|Line Numbers
  1. Dim oApp As Object
  2. Set oApp = CreateObject(Class:="Word.Application")
  3.         oApp.Visible = True
  4.         'Open the Document
  5.         oApp.Documents.Open Filename:="Filename"
  6.         'Use Find object from Selection object to look for the keyword
  7.         With oApp.Selection.Find
  8.             .Forward = True
  9.             .Wrap = wdFindStop
  10.             .Text = "keyword"
  11.             .Execute
  12.         End With
This way the control still stays with Access so we do not have to find a way to pass the keyword to Word as my previous approach. Hope it helps anyone who is facing the same problem.

Thanks Mihail for your prompt response.

Cheers,

-D
Jan 9 '12 #8
Mihail
759 512MB
Good for you !
Jan 9 '12 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Ralf W. Grosse-Kunstleve | last post by:
My initial proposal (http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't exactly get a warm welcome... And Now for Something Completely Different: class autoinit(object):...
38
by: Lasse Vågsæther Karlsen | last post by:
After working through a fair number of the challenges at www.mathschallenge.net, I noticed that some long-running functions can be helped *a lot* by caching their function results and retrieving...
18
by: Toto | last post by:
Hello, my problem is quite simple to explain. I have the following string: "table+camera" and I want to remove the + sign: "tablecamera". How do i do that ?
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
66
by: KimmoA | last post by:
Hey! Some questions about C that have been bugging me for a while... 1) Is inline a valid C keyword or not? I was kind of surprised of not finding it in C, to be honest. My "The C Programming...
5
by: bir | last post by:
I have a folder which contains the xml files with the word CICM in the filename (can also contain some other files) I need to search for all these xml files and create a single zip file for all...
1
by: gagandeep27683 | last post by:
how to display the data in gridview whatever we enter in the textbox. Like we have enter the data in the Textbox,click at the button and it should go to databse and search for data and show it in...
1
by: tswapna | last post by:
Dear Friends Hai this is swapna.i am doing one project(i.ejob site) in ASP.net using C# .For this i need one help. The query is: how to write the code for searching(Keyword search like...
15
by: jzakiya | last post by:
I'm translating a program in Python that has this IF Then chain IF x1 < limit: --- do a --- IF x2 < limit: --- do b --- IF x3 < limit: --- do c --- .----- ------ IF x10 < limt: ---...
0
by: santhanalakshmi | last post by:
Hi, Anyone, please help me out. #SEARCHING my $ldapSearch=$ldap->search( base=>$LDAP_BASE, filter=>"uid1=$USERNAME");
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.