Try this for some help. It's Visual basic.
http://www.programmershelp
Main Topics
Browse All TopicsI am doing automation from Access to Word. I have a chart that I want to copy, and everything works great except the code is too fast and often copies the chart before it's been calculated (which means I actually get the last version of the chart instead).
Here's how I've got it set up:
Inside a big automation module, I've got a sub that processes all the things that get copied into Word. This sub makes a call to open up the chart form, which automatically opens the form, retrieves the data, and formats the chart. Immediately after, the sub copies the chart to the end of the word document:
stDocName = "ifrmDBarChart"
DoCmd.OpenForm stDocName
>>>>>here's where I need the sub to pause while the form finishes opening!!!!!<<<<<<<<<<<<<<
Forms!ifrmDBarChart.SetFoc
Forms!ifrmDBarChart!BarCha
intRangeEnd = mobjDoc.Range.End
Set mobjRange = mobjDoc.Range(intRangeEnd - 1, intRangeEnd)
mobjRange.PasteSpecial , , , , wdPastePicture
How can I make it wait in the middle for the form to finish its calculations? I tried using "Sleep" but that just made the whole computer sleep, so it didn't help.
Any hints out there?
Thanks,
Wendy
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this for some help. It's Visual basic.
http://www.programmershelp
You could try the following solution
'In your form
Private Sub OpenChart()
Dim stDocName As String
stDocName = "ifrmDBarChart"
Forms!frmDBarChart.OnUpdat
DoCmd.OpenForm stDocName
End Sub
Public Property Get ExcelDoc() As Object
Set ExcelDoc = mobjDoc
End Property
'In a module
Public Sub ExportToExcel
Dim intRangeEnd As Integer
Dim frm As Form
Dim objRange As Excel.Range
Set frm = Forms!<Name of you main form here>
'You'll need to get hold of your form Excel range object here
Forms!ifrmDBarChart.SetFoc
Forms!ifrmDBarChart!BarCha
intRangeEnd = frm.ExcelDoc.Range.End
Set objRange = frm.ExcelDoc.Range(intRang
objRange.PasteSpecial , , , , wdPastePicture
Set frm=nothing
set objRange=nothing
End Sub
It's probably not ideal, but worth a try!
Apologies my previous example contains an error.
It seems you cannot set the OnUpdate method to point directly to a sub procedure, or for that matter a function.
In order to get this example to work you'll need to do the following
Create a Macro in Access and call it ExportToExcel
In side the macro choose the "RunCode" option and then enter "ExportToExcel()" in the Function Name box
Now change the Sub procedure titled
Public Sub ExortToExcel()
..to ....
Public Function ExportToExcel()
and ensure the End Sub line becomes End Function (this should happen automatically)
Here is some code that I have used with great success. Thanks to Dev.
Option Compare Database
Option Explicit
'***************** Code Start *******************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Sub sapiSleep Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)
Sub sSleep(lngMilliSec As Long)
If lngMilliSec > 0 Then
Call sapiSleep(lngMilliSec)
End If
End Sub
Sub sTestSleep()
Const cTIME = 1000 'in MilliSeconds
Call sSleep(cTIME)
MsgBox "Before this Msgbox, I was asleep for " _
& cTIME & " Milliseconds."
End Sub
'***************** Code End *********************
‘************Code to be inserted where the Wait is to occur************
'Pause to allow the strLetter to be added to Word
Const cTIME = 1500 'in MilliSeconds
Call sSleep(cTIME)
'Continue with Populating Word Template
Good Luck.
Dawn
Apparently this is more difficult than I expected, so I'm increasing points...thanks for the various suggestions, but I do not yet have a working solution. Some good ideas here, but not quite the answers I need. Somehow there has got to be a way to allow the form to finish its calculations before I copy the bar chart.
The timer/progress bar solution helped me set up a progress bar on the form with the bar chart. However, the subroutine that opens that form continued its processing, so again, the bar chart had not finished calculating. Is there a way to release control to a form until an event is triggered? If I could prevent the subroutine from continuing until the timer reaches a certain value, I might have a solution.
The exporttoexcel solution basically copied the same non-updated bar chart to Excel that is currently being copied into Word. Taking the time to do that did not seem to allow the bar chart form to finish its updates.
The sleep solution is one that I had already tried. It pauses the entire application, so it doesn't work either.
What I need:
from the middle of a very long and complex subroutine, I open a form that instantiates a bar chart. When I open the form, I need the application/subroutine to wait long enough for the bar chart to completely calculate, and then the application can resume the subroutine processing. Basically, in the code above, where I need the pause, can anyone figure out some sort of "wait until the form is ready" calculation?
I've tried using various events on the form itself to do the copying that I need, and none of those has worked either. The "update" event on the chart control has come closest - but it seems to be right before the finished calculation, and I need it to be right after. But if anyone can figure out a way to do this from the form directly, I can use bookmarks to insert the chart into Word at the right position.
Thanks again for the help.
Wendy
Just made some progress...but still looking for improvements...
I used the timer function combined with doevents to create a long pause. I also incorporated the progress bar on the new form (thanks lucas911) so that the user would at least see something was happening while they wait. The thing is that right now, I've got the interval set to 30 seconds, and that's a pretty long time. However, the length of time needed seems to vary widely, from about 1 second to around 25. I can only guess that once I start using this on multiple computers with different speed processors, the variation will become even wider.
I'm still looking for a way to make the length of the pause coincide with the length of time it takes for the form to display itself...here's the newest version of the code:
stDocName = "ifrmDBarChart"
DoCmd.OpenForm stDocName
Forms!ifrmDBarChart.SetFoc
Forms!ifrmDBarChart.Repain
intStart = Timer
intPause = 30
do while Time < intStart + intPause
DoEvents
loop
Forms!ifrmDBarChart!BarCha
intRangeEnd = mobjDoc.Range.End
Set mobjRange = mobjDoc.Range(intRangeEnd - 1, intRangeEnd)
mobjRange.PasteSpecial , , , , wdPastePicture
Thanks in advance...
Wendy
Business Accounts
Answer for Membership
by: lucas911Posted on 2003-09-02 at 11:13:04ID: 9268976
You can use a timer here to pause the application for a couple of seconds. And if you want to be extra about it you can add a progress bar to tell the user that program is doing a calculation.