Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Macro Button Help!"

Macro Button Help!

Button not working

Current user: [none]
Register / Log In · Help

Posted By Post

Woody123

12-Jan-2011 11:18

Hi, I have create a macro for opening an exsiting word doc and it runs fine when I go to tools > play macro and select it from there. Now I have tried to add a button which point to said macro and it comes up with the error:

Untrusted macros are not allowed to perform this operation.
(Postition in the macro:Line 1, Character 1)

The code for the macro is:

Records.WriteToFile cbxWriteFormatCSV+ _
cbxWriteOptionFieldHeading+cbxWriteOptionAlwaysQuote, _
"C:\temp.txt"
Set doc=GetObject("C:\Quote.doc")
doc.Application.Visible=True

bert

12-Jan-2011 12:32

Close your db and reopen it with safety level "completely trusted" (in your file open dialog).
regards
bert

Woody123

12-Jan-2011 14:32

Amazing

Thanks alot bert!

Woody123

12-Jan-2011 14:57

Well im at it. I was also looking to get the record data that is onscreen to be displayed in the word file when the macro button is pushed. Is this possible?

bert

12-Jan-2011 15:29

Which data is on your screen? Some fields or all fields?

Simple way: make a macro which copies needed fields on the clipboard.
Paste it then in Word.
like:
clipboardText = Fields("xxx"") & " " & Fields("yyy") & vbcrlf & Fields("zzz") ' ---> " " is a space ; vbcrlf = newline
For most people this will be enough.

In this case it does not matter which fields are on your screen. You mention only in your macro the fields you need.

More advanced is to add field(s) content to the current word doc complete by a macro.

regards
bert

Woody123

13-Jan-2011 12:35

What im looking for is for the button to open up a word doc and put the information on screen into the word doc. I have already been able to extract the data using word mail merge and create a button to open the word doc. However, It will always start at record 1 in the word doc and not display the current record that is displayed.

Also if you search through the records and press the button (to bring up the word doc) the word doc will get stuck on the first record and it is impossible to change from that record on the word doc

bert

13-Jan-2011 13:42

I wrote an example that does what you want.
If you use the Fields command in a CARDBOX macro, the data of the current record is read and can be transferred to the clipboard or to whatever. So that is not the first, not the last, it is from the current record.

If you want other things which are on your screen, different then fields, you have to add that information separate in your macro.

Then: you want to open a NEW(?) word doc? In your example, you open a existing doc.
Does cut and paste not working - and why not?
regards
bert

Woody123

14-Jan-2011 09:21

Sorry it dose work however it would probably be quicker to just copy and past into the word doc manually. The thing is the file is mail merged and fields need to be put in the correct place.

I have everything in place. The button opens the document, writes to the merdge file and puts the fields in the correct place the only thing is that it dosnt select the record that is up.

I was thinking like ActiveWindow or ActiveRecords command? Here is my code below.

Records.WriteToFile cbxWriteFormatCSV+ _
cbxWriteOptionFieldHeading+cbxWriteOptionAlwaysQuote, _
"C:\temp.txt"
Set doc=GetObject("C:\Quote.doc")
doc.Application.Visible=True

bert

14-Jan-2011 10:30

try this:

Records(RecordPosition).WriteToFile cbxWriteFormatCSV+ _
cbxWriteOptionFieldHeading+cbxWriteOptionAlwaysQuote, _
"C:\temp.txt"

Writse the current record.
Regards
Bert

Woody123

14-Jan-2011 10:49

Thats it!!! Thanks alot bert you are a cardbox GOD!!!!!!

Cheers!! =)

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home