Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access response not from user! 1

Status
Not open for further replies.

AlexmacG

Technical User
Jan 16, 2003
50
GB
A small program to monitor links between two databases ans stores status results in a table. Works fine as code from within Access 97. When I try to run the code after opening the database as an access application object an error message that the action was cancelled by the user appears

"Run time error 2501 The runcommand action was cancelled. e.g You used a DoCmd method and then clicked cancel in the dialogue box'
............oh no I didn't!

Perhaps the vba code is closing the object before the action has been completed? If so how can I prevent this? Thanks in advance!

Code segments attached,

VB6 code
Sub opencontrol()

Dim strDbName As String
strDbName = "C:\db6.mdb"

Set dbase = New Access.Application

dbase.OpenCurrentDatabase strDbName
dbase.DoCmd.RunCommand checkDatabaseX 'line run prior to problem

dbase.CloseCurrentDatabase 'is this the cause?


Set dbase = Nothing
End Sub


CALLed code on access 97 module as below:
This code runs fine from within access!


Sub checkDatabaseX()

Dim wrkJet As Workspace
Dim dbsToCheck As Database

Dim retval As Integer
Err.Clear
On Error GoTo faildbs

' Create Microsoft Jet Workspace object.
Set wrkJet = CreateWorkspace("", "admin", "", dbUseJet)

' Open Database object from saved Microsoft Jet database
' not for exclusive use.

Set dbsToCheck = wrkJet.OpenDatabase("Y:\status monitor1.mdb", False)
‘send message status to table
send_status "message….", "from checkDatabase", "OK", Now

Set dbsToCheck = Nothing
Set wrkJet = Nothing

Exit Sub

faildbs:

send_status "a n other message", "from checkDatabase", "FAIL " & Err.Number, Now


Set dbsToCheck = Nothing
Set wrkJet = Nothing
End Sub
 
Replace this:
dbase.DoCmd.RunCommand checkDatabaseX
By this:
dbase.Run "checkDatabaseX"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top