how to activate a macro when the activerecord changes
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
Re: how to activate a macro when the activerecord changes
Post the code you have!
CS.
Re: how to activate a macro when the activerecord changes
Quote:
Originally Posted by cssriraman
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:
Re: how to activate a macro when the activerecord changes
this is the "quite easy" code that changes the values of the scrollbar to given value saved in a record from access...
VB Code:
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:
VB Code:
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
Re: how to activate a macro when the activerecord changes
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:
VB Code:
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