Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Counter during Automation- Stopping the process

Continuing my question http:Q_26852019.html
Can we send an event?
I want to be able to stop the counter from the access form either using a mouse click or pressing a button.
It seems that Excel has full control & Doevents etc doesn't give me access to the form.
0
tbsgadi
Asked:
tbsgadi
  • 13
  • 10
1 Solution
 
Rory ArchibaldCommented:
It's beginning to sound like you should probably rethink this approach, but it can be done using something like this:
In the ThisWorkbook module of your workbook:
Option Explicit

Public objTB As Object

Open in new window


Then the XL macro becomes for example:
Public Sub TestRoutine()
   Dim n As Long
   Do
      n = n + 1
      With ThisWorkbook.objTB
         .Text = "Processing item number " & n
         .Parent.repaint
         DoEvents
      End With
   Loop While ThisWorkbook.objTB.Tag <> "Stop" And n < 100000
End Sub

Open in new window


and the Access code is:
Private Sub Command0_Click()
   Dim objXL As Object, objWB As Object
   Set objXL = GetObject(, "Excel.Application")
   Set objWB = objXL.workbooks.Open("C:\forums\ee\xlcallbacktest.xls")
   Set objWB.objtb = Me.Text3
   objXL.Visible = False
   Me.Text3.SetFocus
   objXL.Ontime Now(), "TestRoutine"
   objXL.Visible = True
End Sub

Private Sub Command5_Click()
   Me.Text3.Tag = "Stop"
End Sub

Open in new window


0
 
tbsgadiAuthor Commented:
at  
Set objWB.objtb = Me.Text3
I get Error 438 (Object doesn't support this property or method)

I've added Public objTB As Object to  the ThisWorkbook module
0
 
Rory ArchibaldCommented:
Me.Text3 is whatever the textbox is on your form
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
tbsgadiAuthor Commented:
I know
0
 
tbsgadiAuthor Commented:
Maybe I need early binding?
0
 
Rory ArchibaldCommented:
How did you declare objWB in the Access code?
0
 
tbsgadiAuthor Commented:
Same as you-as Object
0
 
Rory ArchibaldCommented:
Then are you absolutely sure you put the 'Public objTB As Object' line in the right place in the workbook (and saved the workbook?)
0
 
tbsgadiAuthor Commented:
Absolutely!
0
 
Rory ArchibaldCommented:
Can you post the workbook you are testing on and the exact Access code you have?
0
 
tbsgadiAuthor Commented:
I'll see if I can manage to dissect it not to give away any trade secrets!
0
 
Rory ArchibaldCommented:
You can also test the attached db and workbook which I was testing on - you'll need to alter or create the path to the workbook as specified in the code.
EE.zip
0
 
tbsgadiAuthor Commented:
Could it be that I'm using

Set objXL = New excel.Application ?
0
 
Rory ArchibaldCommented:
That should not be a problem. Does my sample db work for you?
0
 
tbsgadiAuthor Commented:
It works but I'm getting an application error on     .Parent.repaint
0
 
tbsgadiAuthor Commented:
0
 
Rory ArchibaldCommented:
What error? It works fine for me (Office 2003)
0
 
tbsgadiAuthor Commented:
Maybe Windows 7?

<<It's beginning to sound like you should probably rethink this approach>>
How else would you do it?
0
 
Rory ArchibaldCommented:
I would probably pass control over to Excel and display a progress meter there. Having said that, I can't see why this isn't working for you.
0
 
tbsgadiAuthor Commented:
I notice another big difference between our examples.
In yours you can click on the access form or on a text box while the counter is running. In mine the form is frozen & although the counter works I can't select anything. If I could click anything I wouldn't have any problem.
0
 
Rory ArchibaldCommented:
Are you using OnTime to launch the macro?
0
 
tbsgadiAuthor Commented:
yup
0
 
tbsgadiAuthor Commented:
I found one of the problems.
I was declaring objXL as Excel.Application When I declare it as Object I don't get the error
Error 438 (Object doesn't support this property or method)
Why would that be?

However my form is still frozen & I can't press any of the buttons.
It's open as popup Dialog, I've tried other configurations...any other ideas?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 13
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now