Re: VBA (in Access) to Microstation gives error 462

Tech-Archive recommends: Fix windows errors by optimizing your registry



See comment inline.


"Clif McIrvin" <clare.moe@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:%23sHMr7VuJHA.4928@xxxxxxxxxxxxxxxxxxxxxxx
Boy does that sound familiar! I was attempting to launch an Access Macro from Excel [Office 2003].

I observed an error 462 every ODD launch of my code; it ran successfully every EVEN launch. I never did understand why ... the problem eventually went away and I still don't understand why.

Relevant code snippets and comments from my experience follow:

Sub RunAccessMacro()

' Error: 462 The remote server machine does not exist or is unavailable
' Error: 7867 You already have the database open.

Const comNA As Integer = 462
Const dbOpen As Integer = 7867

Dim appAcc As Access.Application
Dim AccWasOpen As Boolean

Set appAcc = Access.Application
With appAcc


Is this your real code used in Excel VBA? If so, you should get error without question: the code does not instantiate an Access.Application object. It should be:

Set appAcc=New Access.Application

or

Set appAcc=CreateObject("Access.Application")

or

''If you want to connect your Excel to an existing running Access session
Set appAcc=GetObject(,"Access.Application")

As for our code may work when re-launch (I am not sure why it is that every EVEN number of re-launch works), it may because of VB does some thing behind of scene with the not correctly instantiated appAcc object. VB/A sometimes does too much on its own.

Anyway, good code should obtain the appAcc object correctly and close it correctly when you are done with it.


' Testing so far shows Remote Server Not Available error
' every other launch of the macro. I have absolutely no
' clue why; nor why a re-launch works. (5/02/08)

' Testing shows that if Access is closed, or open without
' a database then .CurrentDb returns Nothing

On Error Resume Next
AccWasOpen = (.CurrentDb Is Nothing)
If Err.Number = comNA Then GoTo ExitSub
On Error GoTo 0

' Interesting: after putting in the above test I've not seen
' the exit triggered!

Hopefully either 1) this helps you or (better yet!) 2) someone will be able to explain this to us!

--
Clif


"djw" <david.j.winfield@xxxxxxxxx> wrote in message news:2d59f5d7-d88a-4d14-9cf2-5a02b74b1c3d@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am trying to use VBA in one program (Access) to perform some
operations in another (Microstation V8). When I run the code the
first time I get error 462. The second time I run the code it works
fine. Here is the error message:

Run-time error '462':

The remote server machine does not exist or is unavailable

An example line of code that will give the error is:
With MicroStationDGN.Application.CadInputQueue
.SendCommand "PRINT COLORMODE MONOCHROME"
.SendCommand "PRINT FULL*** ON"
.SendCommand "PRINT maximize
.SendCommand "PRINT EXECUTE "
End With

I have the "Bentley MicroStation DGN 8.0 Object Library" reference
turned on for the project.

Thanks for any help you can provide,
David



--
Clif


.


Quantcast