473,382 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

VBA in MS Word and MS Access different (use of external COM objects)

Hi,
We have a COM object, which in turn use DDE to communicate with
another application of ours. Access to this COM object works fine
from C++, Visual Basic applications, VBS and VBA from MS Word.
But the the same VBA code that works in Word fails in MS Access.

Are there any differences in how VBA in MS Access use COM objects?
Should a COM object be ceated in any special manner to be able to
be used from MS Access?

thanks/Patrik Sjögren
Nov 13 '05 #1
8 3002
Most of the idiosyncrasies of the Access host container are documented
via a couple of MS KB articles. Of the couple of ActiveX controls I have
created with C++ the main issues I have run into have had to do with how
Access redraws itself and its controls. Additionally, some host
container props are not available when your control is first
initialized.

Where exactly is your code failing?

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Patrik Sj?gren" <pa****@sectra.se> wrote in message
news:3d*************************@posting.google.co m...
Hi,
We have a COM object, which in turn use DDE to communicate with
another application of ours. Access to this COM object works fine
from C++, Visual Basic applications, VBS and VBA from MS Word.
But the the same VBA code that works in Word fails in MS Access.

Are there any differences in how VBA in MS Access use COM objects?
Should a COM object be ceated in any special manner to be able to
be used from MS Access?

thanks/Patrik Sjögren


Nov 13 '05 #2
>
Where exactly is your code failing?


Hi,
First of all, our COM object is not a GUI object. All it contains is
around
20 methods that use BSTR to send and receive information, e.g:

virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE
PACSGetVersion(
/* [retval][out] */ BSTR *version) = 0;

The methods in the COM object in turn calls a corresponding DDE
function
of our applications to exchange information. The data returned through
the DDE interface is correct, according to the logs. However, when the
VBA-code is run in MS Access, the returned information from the DDE
call, in this case "PACS_version<1.4>", is replaced with "Error"
before arriving to our
COM object. So, MS Access somehow corrupts the information received
via DDE
to our COM object before it arrives. The same VBA-code works fine when
run from MS Word.
The problem seems to be that MS Access somehow interferes with DDE
communication, and in our case even replaces data.
Nov 13 '05 #3
Sorry Patrik, I have no direct experience in this area.
Have you tried creating a standard Windows DLL and call your code from
there just to eliminate any Access to DDE to COM issues?

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Patrik Sj?gren" <pa****@sectra.se> wrote in message
news:3d**************************@posting.google.c om...

Where exactly is your code failing?


Hi,
First of all, our COM object is not a GUI object. All it contains is
around
20 methods that use BSTR to send and receive information, e.g:

virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE
PACSGetVersion(
/* [retval][out] */ BSTR *version) = 0;

The methods in the COM object in turn calls a corresponding DDE
function
of our applications to exchange information. The data returned through
the DDE interface is correct, according to the logs. However, when the
VBA-code is run in MS Access, the returned information from the DDE
call, in this case "PACS_version<1.4>", is replaced with "Error"
before arriving to our
COM object. So, MS Access somehow corrupts the information received
via DDE
to our COM object before it arrives. The same VBA-code works fine when
run from MS Word.
The problem seems to be that MS Access somehow interferes with DDE
communication, and in our case even replaces data.


Nov 13 '05 #4
On 16 Aug 2004 23:49:27 -0700, pa****@sectra.se (Patrik Sj?gren)
wrote:

Can you post the VBA declaration for the API call?

Also, is the DLL copying the received string to an internal buffer
before returning it, or is it acting as a "pass-through"? Perhaps a
code fragment would help.

-Tom.


Where exactly is your code failing?


Hi,
First of all, our COM object is not a GUI object. All it contains is
around
20 methods that use BSTR to send and receive information, e.g:

virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE
PACSGetVersion(
/* [retval][out] */ BSTR *version) = 0;

The methods in the COM object in turn calls a corresponding DDE
function
of our applications to exchange information. The data returned through
the DDE interface is correct, according to the logs. However, when the
VBA-code is run in MS Access, the returned information from the DDE
call, in this case "PACS_version<1.4>", is replaced with "Error"
before arriving to our
COM object. So, MS Access somehow corrupts the information received
via DDE
to our COM object before it arrives. The same VBA-code works fine when
run from MS Word.
The problem seems to be that MS Access somehow interferes with DDE
communication, and in our case even replaces data.


Nov 13 '05 #5
> Can you post the VBA declaration for the API call?
I'm not sure what you mean here but here is some test VBA-code that calls
our DLL/COM object:

Dim obj
Set obj = CreateObject("Sectra_desktop_sync.SectraDesktopSyn c")
obj.PACSInitialize "ICH"
MsgBox (obj.PACSGetVersion)
MsgBox (obj.PACSIsConnected)
obj.PACSResetDisplayList
MsgBox "after reset display list"
obj.PACSAddToDisplayList "07052001095347", "VascSubtrMesen"
MsgBox "after add to display list"
obj.PACSShowDisplayList 3
MsgBox "ready"
Also, is the DLL copying the received string to an internal buffer
before returning it, or is it acting as a "pass-through"? Perhaps a
code fragment would help.


Our DLL copies the received string before calling SysFreeString(result);
However, the debug version we've written to investigate this problem
pops up a message box just after receiving the string.
The message box says it has received the string "Error" while our
DDE log shows that we have sent "Pacs_version<1.4>". So, somewhere
on the way MS Access replaces the data sent via DDE before it arrives
to our DLL/COM object.

/*
* Retreive version of the DDE interface from the IDS
*/
STDMETHODIMP
CSectraDesktopSync::PACSGetVersion(BSTR *version)
{
USES_CONVERSION;

if (version == NULL) {
return E_POINTER;
}
Nov 13 '05 #6
More info:

I get the same result when placing a breakpoint in our application that
cause the DDE call from the DLL to halt. This triggers a timout in
MS Word/VB that releases after about 10-15 seconds and the result is
the same as in MS Access (with the difference that it returns immediately).
I.e. the returned string is "Error".

Could it be some initiation of DDE that needs to be done in MS Access?
Nov 13 '05 #7
On 18 Aug 2004 04:10:40 -0700, pa****@sectra.se (Patrik Sj?gren)
wrote:

Sorry, I was a bit dense last night. Indeed you are using an ActiveX
DLL, not a classic DLL (which would have a declaration for each
"API").
I can't see anything wrong. For debugging purposes, I would:
return "Test From GetVersion";

If you can prove with a breakpoint on the "return E_POINTER" line that
the content is the correct version number, and with a breakpoint or
MsgBox on the next line in VBA that an "error" result is received, I
would be very surprised. Yet that's what you're saying.

What I meant by the internal buffer is something like (sorry - rusty
on C++):
if (version == NULL) {
char[255] buf;
strcpy(buf, E_POINTER);
return buf;
}

-Tom.
Can you post the VBA declaration for the API call?

I'm not sure what you mean here but here is some test VBA-code that calls
our DLL/COM object:

Dim obj
Set obj = CreateObject("Sectra_desktop_sync.SectraDesktopSyn c")
obj.PACSInitialize "ICH"
MsgBox (obj.PACSGetVersion)
MsgBox (obj.PACSIsConnected)
obj.PACSResetDisplayList
MsgBox "after reset display list"
obj.PACSAddToDisplayList "07052001095347", "VascSubtrMesen"
MsgBox "after add to display list"
obj.PACSShowDisplayList 3
MsgBox "ready"
Also, is the DLL copying the received string to an internal buffer
before returning it, or is it acting as a "pass-through"? Perhaps a
code fragment would help.


Our DLL copies the received string before calling SysFreeString(result);
However, the debug version we've written to investigate this problem
pops up a message box just after receiving the string.
The message box says it has received the string "Error" while our
DDE log shows that we have sent "Pacs_version<1.4>". So, somewhere
on the way MS Access replaces the data sent via DDE before it arrives
to our DLL/COM object.

/*
* Retreive version of the DDE interface from the IDS
*/
STDMETHODIMP
CSectraDesktopSync::PACSGetVersion(BSTR *version)
{
USES_CONVERSION;

if (version == NULL) {
return E_POINTER;
}


Nov 13 '05 #8
> If you can prove with a breakpoint on the "return E_POINTER" line that
the content is the correct version number, and with a breakpoint or
MsgBox on the next line in VBA that an "error" result is received, I
would be very surprised. Yet that's what you're saying.

What I meant by the internal buffer is something like (sorry - rusty
on C++):
if (version == NULL) {
char[255] buf;
strcpy(buf, E_POINTER);
return buf;
}

-Tom.


We have a "debug" version of our COM object that pops up a MsgBox
to show the contents of the returned string. In MS Access (VBA), this
is always "Error", while it is "PACS_Version<1.4>" in VB, MS Word
(VBA) etc.

However, I get the same result, i.e. "Error" when placing a breakpoint
in our application to prevent the DDE call from the COM object to
return. This triggers a timout in MS Word/VB that releases after about
10-15 seconds and the result is the same as in MS Access (with the
difference that it returns immediately). I.e. the returned string is
"Error".

Could it be some initialization of DDE that needs to be done in MS
Access?
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve Claflin | last post by:
I have a database with a moderate number of records in several tables (the biggest table at the moment is about 800 records). In development it got moved between 2K and XP repeatedly. Several...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
8
by: Mike MacSween | last post by:
tblCourses one to many to tblEvents. A course may have an intro workshop (a type of event), a mid course workshop, a final exam. Or any combination. Or something different in the future. At...
5
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
3
by: SAL | last post by:
I’m fairly new to .NET. I’ve been developing in .NET for about 6 months. I have over 10 years experience with VB in general. Here’s what I have done so far: 1. Project is entirely .NET...
5
by: Carstonio | last post by:
I use ASP to display links to Word documents on an intranet. Is there a way in ASP to do text searches on the documents' contents? I want the results to have the link to the Word document plus two...
5
by: jmar | last post by:
I posted a week ago and received one response. I'm looking for the opinion of several experienced .NET people before I proceed so I'm posting again. Sorry for the repost... I am updating a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.