Click form buttons remotely

DataMiner

Registered User.
Local time
Today, 21:03
Joined
Jul 26, 2001
Messages
336
I have some reports I need to run automatically every morning. The same reports can be run manually by clicking some buttons on a form. I was hoping I could, via vb, remotely manipulate the form. There are certainly other ways I can do this, but it seems like, for ease of maintenance, it would be nice if I could just pretend I was an automated remote user, and manipulate the form the same way a user would.
The code I'm using is shown below. It works OK except when I am running in on a Citrix terminal server, run-time environment. I get error #429, "ActiveX component can't create object". The terminal server has ONLY runtime access installed.
If I run it from my desktop, which of course has the full version of Access, it works fine...even if I use the \runtime command line option.

So... any ideas on how I might get this to work on the terminal server? Do you think this is a runtime issue, or a server issue, or what?

Using Access2002. Here's the code:
Function PrintAOIReports(lngShift As Long) As Boolean
Dim DB As DAO.Database, appAccess As Access.Application
Dim Ctl As Control, i As Long


If errorhandlingon Then On Error GoTo ErrHandle

PrintAOIReports = False
Set appAccess = CreateObject("Access.Application")
'appAccess.Visible = False 'doesn't seem to work here;when you open the db it resets to true
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase pcainternal_fe
appAccess.Visible = False

With appAccess.Forms("PCAINternalswitchboard")

!hardcopy = True
Select Case lngShift
Case 1, 2
!startpareto = Date
Case 3
!startpareto = Date - 1
End Select
!stoppareto = Now()
!reporttype = 1
!Noun.Enabled = False
!PartNumberToggle = 0
!PartNumber.Enabled = False
!RefDesToggle = 0
!RefDes.Enabled = False
!RepCodeToggle = 0
!RepCode.Enabled = False
!inspectpoint.Enabled = True
!InspChoice.Value = 3
Set Ctl = .Controls("inspectpoint")
For i = 0 To Ctl.ListCount - 1
If Left(Ctl.ItemData(i), 3) = "AOI" Then Ctl.Selected(i) = True
Next i
!RespChoice.Value = 3
!Value.Enabled = True
!Value.Value = "SMT"
!DivisionToggle = 0
!Division.Enabled = False
!row.Value = "[attributeyields].[noun] & '_A' & [Assyno] & [RefDes]"
!Column.Value = "attributerepairs.repcode"
!limit.Value = 10
.gomaster "ParetoPCAInternal_Default", "evtews3" '"EVTEWS3"
'.gopareto_click ' note that to make this work,you must set the click event to PUBLIC!
'!gopareto.SetFocus 'setfocus and sendkeys work without making public
'SendKeys "{ENTER}"
End With
LogError "AOI Report for Shift " & lngShift, "PrintAOIReports"
GoTo CloseAll
ErrHandle:
LogError Err.Description, "PrintAOIReports", Err.Number
CloseAll:
appAccess.Quit
Set appAccess = Nothing

End Function
 
This may be a silly suggestion but the command buttons on your form have code behind them. You want to do the same thing as a user clicking certain buttons. Clicking a button only serves to run the code.

Why not create a code module that contains or calls all the same code that is already behind the buttons that you want to press, in the order you want that code run.

Then, run the code module using whatever trigger suits you (timer, Form_Open, whatever).
 
Yes of course I can do this. But that means I have to maintain two sets of the same code, and that's what I was hoping to avoid.
 
Well, if you place the code for each button in its own sub, then call that sub from the button, and call the sub from the 'automate_clicking' sub then the code would only be in one place...
 

Users who are viewing this thread

Back
Top Bottom