Alternative for Access to word with bookmarks?

vinzz

Registered User.
Local time
Today, 11:57
Joined
Apr 24, 2008
Messages
47
Hello,

Is it possible to not use the intern mailmerge function.
What i try to get is the following:

When i press a button on a form it has to export the data from access (only that form) to word (with an *.dot file)

But i don't want to use the bookmark function in word.
what i try to do is make a text in word with $id$ text (example)

How can i write a VBA script that changes the $id$ text in word (More than once!)

example worddoc (dot):

Code:
our id= $id$

hello $name$, we received you're mail and orderd it under id: $id$

as you can see in the example text above i want to change $id$ and $name$ with dynamically text from the opened form in access.

If i find this function i can write the whole letter with simple $$ signs when i want text exported from access.

than as last it has to save the opened dot as a doc with the current id as filename.

Someone that knows how to handle this? thanks in advance.

(at the moment i'm working with a bookmark function in word, but it seems to be impossible to get a bookmark more than once in a word doc.)
 
Something like this you mean?

Code:
dim rng as word.range

Set rng = ActiveDocument.Content

rng.Find.Execute FindText:="$id$", ReplaceWith:="bill", Replace:=wdReplaceAll
 
you can use a bookmark more than once in Word. Create a bookmark like normal, then if you want to have it somewhere else in the Word doc, just do insert>field and choose Ref from the list. This will bring up a list of bookmark names. simply select your bookmark and click OK. now all you have do is update the text of you original bookmark and update all fields (in VBA) of course.
 
yes, that is what i'm looking for.

I already made a script with this function
Code:
Option Compare Database


Public Sub Knop5_Click()
Screen.MousePointer = 11

pdot = "c:\test2.dot"
If IsNull(pdot) Then
    MsgBox "dot not found."
    Screen.MousePointer = 0
    Exit Sub
End If

On Error Resume Next

    Set MyWord = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        noggeenwordopen = True
        Set MyWord = CreateObject("Word.Application")
    End If
    Err.Clear

On Error GoTo 0
On Error Resume Next
MyWord.Documents.Add Trim(pdot)
MyWord.Selection.Find.ClearFormatting
With MyWord.activedocument.content.Find

    .ClearFormatting
    .Execute findtext:="$id$", Replacewith:=Me!id, MatchCase:=False, MatchWildcards:=False, Forward:=True, Wrap:=wdFindContinue, Format:=False, Replace:=2
    .Execute findtext:="$Tekst1$", Replacewith:=Me!test1, MatchCase:=False, MatchWildcards:=False, Forward:=True, Wrap:=wdFindContinue, Format:=False, Replace:=2
    .Execute findtext:="$Tekst2$", Replacewith:="************", MatchCase:=False, MatchWildcards:=False, Forward:=True, Wrap:=wdFindContinue, Format:=False, Replace:=2
    .Execute findtext:="$Tekst3$", Replacewith:=Trim(Format(Now, "yyyy")), MatchCase:=False, MatchWildcards:=False, Forward:=True, Wrap:=wdFindContinue, Format:=False, Replace:=2
    .Execute findtext:="$datum_vandaag$", Replacewith:=Trim(Format(Now, "dd.mm.yyyy")), MatchCase:=False, MatchWildcards:=False, Forward:=True, Wrap:=wdFindContinue, Format:=False, Replace:=2
End With
On Error GoTo 0


On Error Resume Next
MyWord.Documents.Parent.Visible = True
MyWord.Application.WindowState = 1 'wdWindowStateMaximize
MyWord.ActiveWindow.WindowState = 1 'wdWindowStateMaximize
On Error GoTo 0

On Error Resume Next
AppActivate "Microsoft Word"
On Error GoTo 0
            
On Error Resume Next
rs_in.Close
rs_uit.Close
On Error GoTo 0
    
    
Screen.MousePointer = 0

Exit Sub

Err_Briefmaken:
    Screen.MousePointer = 0
    MsgBox Error$
    Exit Sub
    Resume Next
End Sub

How can i add a function to save the opened doc automatically as (Me!id & ".doc")

and how can i add a function to get all the records from a subform in a opened form
i think i have to use a loop or a FOR EACH record function. but i don't know how to use this function with a subform
 
Code:
activedocument.saveas(me!id & ".doc")

Will do the saving stuff.

For your records use something like

Code:
set rs = db.openrecordset(forms!main_form!subformCollection.form.rowsource)

The bit about the subform may be wrong as it's been an age since I used them but I think it's the right way to do it.
 
Thanks alot chergh! i will try the code when i have the time :P
 
the save function works perfect.

but now i see another thing that doesn't work

i have an pull down box on my head form that gets his info from a table.
the pull down got these settings (i have a dutch version, could be an other name in English:

Type source: Table/query
source: test (this table got 6columns total)
row count: 3
row-width: 0cm;2cm;2cm (0cm is the column with an ID)
row: 1 (this is the setting that puts the ID as save)

if i select an option from this pull down it will show correctly on the form, but when i make a worddoc of it (with find and replace vba function) it shows the id and not the second column like on the form.

Is there anyway to fix this problem?

thanks in advance.
 
nvm, found everything i wanted :P

Thanks for the contribuition everyone! this topic is solved
 
Bump...
I have been playing with Bookmarks and must admit they are a pain
so wne t looking for alternatives - this looks interesting
(I already have super easy word - but need to split the docs in to two lots)

this option I am looking at seems more manageable

I outline the requirement -

I have reports (access - fixed with variables etc) sorted
I have letters (I need flexibility - but merge from access - Supereasyword) sorted
I have reports* that are too complicated to make into Access reports -
10-20 fields are mergable the rest - well one one of theses reports i have seen at least 10 variations (and i cannot tie them down -) there are so far 6 reports with x variations each and the number of the reports will expand - so i want the default to merge and then they can change to their hearts content
so its this last option that i am not using super easy word on but thinking about $xx$ option
 

Users who are viewing this thread

Back
Top Bottom