Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need Help with Run-time Error '462' Posted by darthmoobey on 1 Aug 2005 at 9:00 AM
Hello, I am importing an Excel Spreadsheet into a Microsoft Access Database. The first initial moment I import it works fine, but when I try to import again I get the error message

Run-time error '462':
The remote server machine does not exist or is unavailable.

I researched on MSDN and found an article that explained this.

CAUSE
Visual Basic has established a reference to Excel due to a line of code that calls an Excel object, method, or property without qualifying it with an Excel object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
Back to the top Back to the top
RESOLUTION
Modify the code so that each call to an Excel object, method, or property is qualified with the appropriate object variable.

Now this was great to know, but I couldn't quite understand how the resolution was explaining itself. How do I modify my code to keep from that error popping out and not needing to shut down my program every time I want to append an excel spread sheet to hte database through import?

Dim strpath As String

strpath = DirectoryList.Path & _
    IIf(Right$(DirectoryList.Path, 1) = "\", "", "\") & ListFile.FileName

Dim objAccApp1 As Access.Application
Dim TableName As String
TableName = "CentexInfo"

Set objAccApp1 = GetObject("x:\databases\Centex.mdb")

'objAccApp1.Visible = False

'DoCmd.DeleteObject acTable, "CentexInfo"

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, TableName, strpath, True <-- This is where I get the error 

objAccApp1.Quit
Set objAccApp1 = Nothing


Thank you veyr much
The DarthMoob
Report
Re: Need Help with Run-time Error '462' Posted by darthmoobey on 3 Aug 2005 at 6:28 AM
Nevermind everyone, I did some more advanced reading and research and found the problem. It appears with VB controls like such in reference to Office Programs VB uses a hidden global variable for object commands if not specified. I had to adjust my code liek such


objAccApp1.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, TableName, strpath, True



I needed to add objAccApp1 before my DoCmd so that VB would not assign it to the hidden global variable. As such I would need to close my entire program, in order to use that command again. By specifying the variable object, it does not use the global variable and destroys the command variable after use. Again thank you for anyone looking into helping me, and I hope this problem helps anyone else reading along on here.

The Darthmoob

: Hello, I am importing an Excel Spreadsheet into a Microsoft Access Database. The first initial moment I import it works fine, but when I try to import again I get the error message
:
: Run-time error '462':
: The remote server machine does not exist or is unavailable.
:
: I researched on MSDN and found an article that explained this.
:
: CAUSE
: Visual Basic has established a reference to Excel due to a line of code that calls an Excel object, method, or property without qualifying it with an Excel object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
: Back to the top Back to the top
: RESOLUTION
: Modify the code so that each call to an Excel object, method, or property is qualified with the appropriate object variable.
:
: Now this was great to know, but I couldn't quite understand how the resolution was explaining itself. How do I modify my code to keep from that error popping out and not needing to shut down my program every time I want to append an excel spread sheet to hte database through import?
:
:
: Dim strpath As String
: 
: strpath = DirectoryList.Path & _
:     IIf(Right$(DirectoryList.Path, 1) = "\", "", "\") & ListFile.FileName
: 
: Dim objAccApp1 As Access.Application
: Dim TableName As String
: TableName = "CentexInfo"
: 
: Set objAccApp1 = GetObject("x:\databases\Centex.mdb")
: 
: 'objAccApp1.Visible = False
: 
: 'DoCmd.DeleteObject acTable, "CentexInfo"
: 
: DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, TableName, strpath, True <-- This is where I get the error 
: 
: objAccApp1.Quit
: Set objAccApp1 = Nothing
: 

:
: Thank you veyr much
: The DarthMoob
:

Report
Re: Need Help with Run-time Error '462' Posted by ws1o on 21 Dec 2011 at 9:21 AM
Thanks, The Darthnoob, using AccApp.Docmd instead of just Docmd solved a very annoying and persistent error I was seeing!
Report
Re: Need Help with Run-time Error '462' Posted by ws1o on 21 Dec 2011 at 9:23 AM
Thanks, The Darthnoob, using AccApp.Docmd instead of just Docmd solved a very annoying and persistent error I was seeing!
Report
Re: Need Help with Run-time Error '462' Posted by ws1o on 21 Dec 2011 at 9:25 AM
Thanks, The Darthnoob, using AccApp.Docmd instead of just Docmd solved a very annoying and persistent error I was seeing!
Report
Re: Need Help with Run-time Error '462' Posted by ws1o on 21 Dec 2011 at 9:48 AM
Thanks very much, The Darthnoob, using AccApp.Docmd instead of just Docmd solved a very annoying pproblem for me!
Report
Re: Need Help with Run-time Error '462' Posted by ws1o on 21 Dec 2011 at 9:50 AM
Thanks very much, The Darthnoob, using AccApp.Docmd instead of just Docmd solved a very annoying pproblem for me!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.