VB6 program fails opening Excel 2007 with Automation Error Library not registered - vb6

I created this VB6 program on my Windows 7 32bit machine with Office 2010 32bit, which runs fine. Tested it on a Windows 8 64 bit machine with Office 2013 32bit, it works. On one machine with, Windows 7 64 bit and Office 2007(32 bit only) it throws an error during the following piece of code.
The actual error message:
Run-time Error –2147319779 (8002801d) Automation error, Library not
registered
VB6 Code:
If (excel_app Is Nothing) Then
Set excel_app = CreateObject("Excel.Application")
Else
Set excel_app = GetObject(, "Excel.Application")
End If
excel_app.Visible = True
excel_version = excel_app.Application.Version
Set wBook = excel_app.Workbooks.Open(directory_path & "\templates\book1.xlsm")
So it is throwing the error when I open book1. It actual does open it and it has a macro run on Workbook_Open(), this runs right through seemly fine. After it finishes and processing of the program returns to the VB6 program it throws the error.
Here are the project references:
Has anyone come across this and what would be the fix?
[EDIT]
I am obviously doing something wrong here my error handler is throwing an error.
I did try one other thing and that was removed "Set wBook = " and it didn't throw an error. I have placed "Set wBook = " back since then, as I do need it further on in my code.
Dim wBook As Workbook
Dim excel_app As Object
On Error GoTo trialhandler
If (excel_app Is Nothing) Then
Set excel_app = CreateObject("Excel.Application")
Else
Set excel_app = GetObject(, "Excel.Application")
End If
excel_app.Visible = True
excel_version = excel_app.Application.Version
Set wBook = excel_app.Workbooks.Open(directory_path & "\templates\book1.xlsm")
MsgBox ("Exiting")
Exit Sub
trialhandler:
Dim source_string As String
source_string = excel_app.Source 'Error here
MsgBox ("My Error 1:" & source_string)
excel_app.Err
MsgBox ("My Error 2:" & excel_app.Err.Number & " " & excel_app.Err.Description)
Exit Sub
I had Office 2013 installed on this previously, then uninstalled it and placed 2007 on it, could this have any impact? Or the fact that I have created this program with reference to Excel 2010 and now I'm trying to run it against Office 2007? Though it works on the other machine with 2013. Grasping at straws here.
[EDIT 2]
It has passed the initial error to throw exactly the same error later on. This piece imports an mdb table. There must be some early binding left over
With wBook.Worksheets("Seal Register").ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=" & db_full_path & ";" _
, _
"Mode=ReadWrite;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";" _
, _
"Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;" _
, _
"Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;" _
, _
"Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;" _
, _
"Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False"), _
Destination:=Range("A" & row_number)).QueryTable
.MaintainConnection = False
.CommandType = xlCmdTable
.CommandText = Array(db_table_name)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = 1
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.SourceDataFile = db_full_path
.ListObject.DisplayName = "Table_" & db_table_name
.Refresh BackgroundQuery:=False
End With

There no reason to think this is a vb error.
Returns or sets the name of the object or application that originally generated the error.
object.Source [= stringexpression]
Arguments
object
Always the Err object.
stringexpression
A string expression representing the application that generated the error.
Remarks
The Source property specifies a string expression that is usually the class name or programmatic ID of the object that caused the error. Use Source to provide your users with information when your code is unable to handle an error generated in an accessed object. For example, if you access Microsoft Excel and it generates a Division by zero error, Microsoft Excel sets Err.Number to its error code for that error and sets Source to Excel.Application. Note that if the error is generated in another object called by Microsoft Excel, Excel intercepts the error and sets Err.Number to its own code for Division by zero. However, it leaves the other Err object (including Source) as set by the object that generated the error.
Source always contains the name of the object that originally generated the error — your code can try to handle the error according to the error documentation of the object you accessed. If your error handler fails, you can use the Err object information to describe the error to your user, using Source and the other Err to inform the user which object originally caused the error, its description of the error, and so forth.
From Automating Microsoft Office 97 and Microsoft Office 2000
Lori Turner
Microsoft Corporation
March 2000
PROBLEM:
My Automation client worked fine with the Office 97 version of my application. However, I rebuilt my project and it works fine with Office 2000 but now fails with Office 97. What could be wrong?
New versions of Office include new features and enhance some of the existing ones. To provide clients with programmatic access to these new and enhanced features, the object models must be updated. Because of this update, a method may have more arguments for Office 2000 than it did with Office 97.
The new arguments to existing methods are usually optional. If you use late binding to the Office Automation server, your code should work successfully with either Office 97 or Office 2000. However, if you use early binding, the differences between the 97 and 2000 type libraries could cause you problems in the following situations:
If you create an Automation client in Visual Basic and reference the Office 2000 type library, your code might fail when using an Office 97 server if you call a method or property that has changed.
If you create an MFC Automation client and use the ClassWizard to wrap classes from the Office 2000 type library, your code might fail when using an Office 97 server if you call a method or property that has changed.
To avoid this problem, you should develop your Automation client against the lowest version of the Office server you intend to support. For the best results in maintaining compatibility with multiple versions of Office, you should use late binding. However, if you choose to use early binding, bind to the type library for the earliest version of the Office server you want to support. To illustrate, if you are writing an Automation client with Visual Basic and want that client to work with Excel 97 and Excel 2000, you should reference the Excel 97 type library in your Visual Basic project. Likewise, if you are writing an Automation client using MFC, you should use the ClassWizard to wrap the Excel 97 type library.
For more information, please see the following article in the Microsoft Knowledge Base:
Q224925 INFO: Type Libraries for Office 2000 Have Changed

Related

Outlook OLE Automation: BodyFormat not supported?

I am trying to send an email in Outlook using OLE Automation. At the moment, I am using VBS for testing purposes. When it works, I will switch to another language that supports OLE/COM.
The problem with my code is, that I get error 800a0005 "Invalid procedure call" with argument 'BodyFormat'.
According to the documentation of Microsoft, BodyFormat is existing since Outlook 2003. I am testing with Outlook 2010.
My code:
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
With newMail
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With
The background: At the moment, some customers receive emails in TNEF format and can't open the email attachment winmail.dat. So I am trying to force Outlook to use HTML instead of RichText.
What can I do?
Constant olFormatHTML is not defined by default.
Add the following line at the beginning of your VBS code:
Const olFormatHTML = 2

What are the prerequisites for installing CDO.DLL in Windows Server 2012 for VB application

I am upgrading a server from Windows 2003 to 2012 R2.
One of our VB6 applications used CDO.dll for MAPI, i.e. for sending mails.
My question is :
How do I install/register CDO.DLL?
What are the prerequisites for installing CDO.DLL?
Do I need to install Outlook in my server for the application to send mail?
Set objMAPI = New MAPI.Session
objMAPI.Logon ShowDialog:=False, NewSession:=False, ProfileInfo:=gobjINI.gstrExchangeServer & vbLf & gobjINI.gstrProfile
'Add a new mesage to the OUtbo Messages Collection
Set objMSG = objMAPI.Outbox.Messages.Add
'Add the recipient list specified in INI File
'Check if this is a multiple Recipient List (names or groups seperated by semicolons!)
If InStr(1, Recipients, ";") Then
objMSG.Recipients.AddMultiple Recipients, CdoTo
objMSG.Recipients.Resolve
Else
'This section is for handling of single recipient name
'Be aware that this may be an email group list name !
Set objRecipients = objMSG.Recipients.Add(Recipients)
objRecipients.Resolve
End If
'Add Subject Line, Message Content and Send Message
objMSG.Subject = Subject
objMSG.Text = Message
'The Update method adds all our assignments to collecttion
objMSG.Update
'Now let's actually send the message
objMSG.Send
'End MAPI Session
objMAPI.Logoff
Set objMAPI = Nothing
MailSend = True
CDO 1.21 is no longer being developed or supported by Microsoft. You can download the standalone version of MAPI along with CDO 1.21 from https://www.microsoft.com/en-us/download/details.aspx?id=42040. It was last updated in 2014 and no new bug fixes are expected. Functionality wise it has not been updated for the last 15 years.
You can switch to the Outlook Object Model (Namespace object roughly corresponds to the MAPI.Session object).
You can also use Redemption (I am its author) - its RDOSession object is similar to the MAPI.Session object (with a lot more extra features).

VB6: Automation error The remote procedure call failed

In my VB6 application sometimes in some customer PC we get error like
Automation error
The remote procedure call failed.
The error comes for the code shown below
Dim WithEvents Web_popup As SHDocVw.InternetExplorer
Set Web_popup = Nothing
Set Web_popup = New SHDocVw.InternetExplorer
Set ppDisp = Web_popup.Application
Also for the below code
Dim iE As New SHDocVw.InternetExplorer iE.Navigate "www.example.com", 4 + 8
iE.Visible = True
What may be the reason for these errors? How to solve it?
You should include more information when asking for help. More importantly, you should point exactly which lines are causing the error. That being said, it sounds to me that you are not checking the ready state of the download of html to Explorer. Interacting with a web page before the web page has been completely download will cause this symptom.
If you are checking the ready state, the only other way I was able to produce the error was turning on protected mode in Internet Explorer. Some websites cause the error when Protected mode is on.

Database access issue with Visual Studio application

I has been created a program that works with MS Access 2010 (.accdb)extension. The program is fully works fine.
The issue is:
When the program is installed into another PC that has no MS Office installed, then the Exception that defined in the program returns connection error. Yes of course because the program can't read the (.accdb) file without office installed.
Need solution:
Is there any way to import this (.accdb) in order to read and modify it. Or is there any other simple solution that works when the application is installed to any non office installed PC?
The Demo of My program Code is:
Connection String:
Imports SpeechLib
Imports System.IO
Module MdlIPray5ve
Public con As OleDb.OleDbConnection
Public cmd As OleDb.OleDbCommand
Public sql As String
Public speaker As New SpVoice
Public Function connection() As String
Try
connection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=azan_time.accdb; Persist Security Info=False;"
Catch ex As Exception
MessageBox.Show("Could not connect to the Database. Check your Connection!")
End Try
End Function
Something that Accesses the Database:
Private Sub UpdateAlarmTone()
Try
Dim cmdText = "UPDATE alarm_tone SET subhi= #subhi1, zuhur =#zuhur1, aser = #aser1, megrib = #megrib1, isha = #isha1"
Using con As New OleDb.OleDbConnection(connection)
Using cmd As New OleDb.OleDbCommand(cmdText, con)
con.Open()
cmd.Parameters.AddWithValue("#subhi1", txtSubhi.Text)
cmd.Parameters.AddWithValue("#zuhur1", txtZuhur.Text)
cmd.Parameters.AddWithValue("#aser1", txtAser.Text)
cmd.Parameters.AddWithValue("#megrib1", txtMegrib.Text)
cmd.Parameters.AddWithValue("#isha1", txtIsha.Text)
Dim infor As String
infor = cmd.ExecuteNonQuery
If (infor > 0) Then
MsgBox("Alarm Tone record updated successfuly")
Else
MsgBox("Update failed!")
End If
End Using
End Using
Catch ex As Exception
MessageBox.Show("There is a problem with your connection!")
End Try
End Sub
create the Access database via ODBC, that comes with Windows itself.
You can also use other databases (eg., MySQL, Firebird, SQLite, and others) that are available that wouldn't necessarily cost your client anything if they installed it (or, for some, if you included it in your installation for them).
Using the MS Office COM automation requires that the MS Office product be installed on the machine running the automation.
There are third-party code libraries that replace that functionality with their own code, meaning your app could create it's own Access-compatible files. However, your users would still need Access to use them

How to create accdb file in vb 6.0 during runtime

Someone please help me to create MS Access database .accdb extension file during runtime using VB 6.0 at a particular location (e.g. E:\MMDataBase)
& also help me in creating tables in the same database.
MS Access 2007 is already installed in my computer
thanks
The ACE database engine is essentially an extended version of Jet 4.0 and contains much of Jet 4.0 with support for the new format on top of that. As a result both the SQL DML and DDL syntax is quite similar to Jet 4.0 SQL.
I'm not sure whether installing Access 2007 installs the ACE Provider or not. Perhaps it is an optional item in the Access 2007 installer? In any case a separate Microsoft download exists that can be used to install the necessary software even when you don't have Access 2007 at all.
See 2007 Office System Driver: Data Connectivity Components
Once that's in place the process is basically identical to doing this with Jet. Example:
Private Sub CreateDB()
'Reference required:
'
' Microsoft ActiveX Data Objects 2.5 Library (or later).
'
'OLEDB Provider required:
'
' Access Database Engine 2007.
Dim catDB As Object
Dim cnDB As ADODB.Connection
Set catDB = CreateObject("ADOX.Catalog")
With catDB
.Create "Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source='D:\sample.accdb'"
Set cnDB = .ActiveConnection
End With
Set catDB = Nothing
With cnDB
.Execute "CREATE TABLE ClassDates(" _
& "Id IDENTITY CONSTRAINT PK_UID PRIMARY KEY," _
& "Student TEXT(12) WITH COMPRESSION NOT NULL," _
& "ClassDate DATETIME NOT NULL," _
& "PaidFor YESNO DEFAULT False," _
& "CONSTRAINT StudentDates UNIQUE (" _
& "Student, ClassDate))", , _
adCmdText Or adExecuteNoRecords
.Close
End With
End Sub

Resources