PDA

Click to See Complete Forum and Search --> : how to activate a macro when the activerecord changes


hakiri
Dec 1st, 2005, 10:19 AM
hello,

im using using mailmerge to get data from access to word.
I'm using a scrollbar to visually show of some data. I already wrote the code to attach the value of the field to the scrollbar but I can't find how to trigger this macro each time the active record changes to another one...

Can anyone help me plz

thx in advance !!!
greetz
hakiri

cssriraman
Dec 2nd, 2005, 03:40 AM
Post the code you have!

CS.

hakiri
Dec 5th, 2005, 02:03 AM
Post the code you have!

CS.

little problem... the word doc decided to crash :s
guess i tried to much without taking a backup... so i will have to write it all over again... I'll post it when its ready :thumb:

hakiri
Dec 5th, 2005, 07:22 AM
this is the "quite easy" code that changes the values of the scrollbar to given value saved in a record from access...

Sub scrollbar_change()
ActiveDocument.ScrollBar2.Value = ActiveDocument.MailMerge.DataSource.DataFields("abalet").Value
ActiveDocument.ScrollBar3.Value = ActiveDocument.MailMerge.DataSource.DataFields("adm").Value
ActiveDocument.ScrollBar4.Value = ActiveDocument.MailMerge.DataSource.DataFields("anabo").Value
ActiveDocument.ScrollBar5.Value = ActiveDocument.MailMerge.DataSource.DataFields("fwt").Value
ActiveDocument.ScrollBar51.Value = ActiveDocument.MailMerge.DataSource.DataFields("algo").Value
ActiveDocument.ScrollBar511.Value = ActiveDocument.MailMerge.DataSource.DataFields("conclus").Value
ActiveDocument.ScrollBar5111.Value = ActiveDocument.MailMerge.DataSource.DataFields("num").Value
ActiveDocument.ScrollBar41.Value = ActiveDocument.MailMerge.DataSource.DataFields("rapid").Value


End Sub

now I'm looking 4 a way to call scrollbar_change whenever one of the actions written below takes place. So whenever one of theses actions should take place it should trigger scrollbar_change. I thought I had to write a macro called "document_open()" soit always reads when something should happen... but I could be mistaken :ehh:






ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdPreviousRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord


thx for the help,
really appreciate it
hakiri

hakiri
Dec 5th, 2005, 09:52 AM
okay, i searched for an alternate option... i made new buttons which couples the going to the next record and changing the scrollbars...

the problem now is... it changes when i use it in combination with wdLastRecord and wdFirstRecord, but not with wdNextRecord and wdPreviousRecord. the error i get is that i can't set the value. illegal value fault 380.

help plz :ehh:


Sub scrollbar1_change()
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
ActiveDocument.ScrollBar2.Value = ActiveDocument.MailMerge.DataSource.DataFields("abalet").Value
ActiveDocument.ScrollBar3.Value = ActiveDocument.MailMerge.DataSource.DataFields("adm").Value
ActiveDocument.ScrollBar4.Value = ActiveDocument.MailMerge.DataSource.DataFields("anabo").Value
ActiveDocument.ScrollBar41.Value = ActiveDocument.MailMerge.DataSource.DataFields("fwt").Value
ActiveDocument.ScrollBar5.Value = ActiveDocument.MailMerge.DataSource.DataFields("algo").Value
ActiveDocument.ScrollBar51.Value = ActiveDocument.MailMerge.DataSource.DataFields("conclus").Value
ActiveDocument.ScrollBar511.Value = ActiveDocument.MailMerge.DataSource.DataFields("num").Value
ActiveDocument.ScrollBar5111.Value = ActiveDocument.MailMerge.DataSource.DataFields("rapid").Value




End Sub
Sub scrollbar2_change()
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdPreviousRecord
ActiveDocument.ScrollBar2.Value = ActiveDocument.MailMerge.DataSource.DataFields("abalet").Value
ActiveDocument.ScrollBar3.Value = ActiveDocument.MailMerge.DataSource.DataFields("adm").Value
ActiveDocument.ScrollBar4.Value = ActiveDocument.MailMerge.DataSource.DataFields("anabo").Value
ActiveDocument.ScrollBar41.Value = ActiveDocument.MailMerge.DataSource.DataFields("fwt").Value
ActiveDocument.ScrollBar5.Value = ActiveDocument.MailMerge.DataSource.DataFields("algo").Value
ActiveDocument.ScrollBar51.Value = ActiveDocument.MailMerge.DataSource.DataFields("conclus").Value
ActiveDocument.ScrollBar511.Value = ActiveDocument.MailMerge.DataSource.DataFields("num").Value
ActiveDocument.ScrollBar5111.Value = ActiveDocument.MailMerge.DataSource.DataFields("rapid").Value


End Sub
Sub scrollbar4_change()
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
ActiveDocument.ScrollBar2.Value = ActiveDocument.MailMerge.DataSource.DataFields("abalet").Value
ActiveDocument.ScrollBar3.Value = ActiveDocument.MailMerge.DataSource.DataFields("adm").Value
ActiveDocument.ScrollBar4.Value = ActiveDocument.MailMerge.DataSource.DataFields("anabo").Value
ActiveDocument.ScrollBar41.Value = ActiveDocument.MailMerge.DataSource.DataFields("fwt").Value
ActiveDocument.ScrollBar5.Value = ActiveDocument.MailMerge.DataSource.DataFields("algo").Value
ActiveDocument.ScrollBar51.Value = ActiveDocument.MailMerge.DataSource.DataFields("conclus").Value
ActiveDocument.ScrollBar511.Value = ActiveDocument.MailMerge.DataSource.DataFields("num").Value
ActiveDocument.ScrollBar5111.Value = ActiveDocument.MailMerge.DataSource.DataFields("rapid").Value


End Sub
Sub scrollbar3_change()
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
ActiveDocument.ScrollBar2.Value = ActiveDocument.MailMerge.DataSource.DataFields("abalet").Value
ActiveDocument.ScrollBar3.Value = ActiveDocument.MailMerge.DataSource.DataFields("adm").Value
ActiveDocument.ScrollBar4.Value = ActiveDocument.MailMerge.DataSource.DataFields("anabo").Value
ActiveDocument.ScrollBar41.Value = ActiveDocument.MailMerge.DataSource.DataFields("fwt").Value
ActiveDocument.ScrollBar5.Value = ActiveDocument.MailMerge.DataSource.DataFields("algo").Value
ActiveDocument.ScrollBar51.Value = ActiveDocument.MailMerge.DataSource.DataFields("conclus").Value
ActiveDocument.ScrollBar511.Value = ActiveDocument.MailMerge.DataSource.DataFields("num").Value
ActiveDocument.ScrollBar5111.Value = ActiveDocument.MailMerge.DataSource.DataFields("rapid").Value


End Sub