Had some trouble with Word automation. Sorted it, in the process thought I
would try late binding. Some people reccomend it. So this:
*************** *************** *************** ************
Public Sub MailMerge(strQu ery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Applicatio n
snip
Set wrdApp = New Word.Applicatio n
Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge
..Destination = wdSendToNewDocu ment
..SuppressBlank Lines = True
With .DataSource
..FirstRecord = wdDefaultFirstR ecord
..LastRecord = wdDefaultLastRe cord
End With
If .State = wdMainAndDataSo urce Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
*************** *************** *************** ************
works, with a reference to the Word olb
If i change it to:
*************** *************** *************** ************
Public Sub MailMerge(strQu ery As String, strTemplate As String)
snip
Dim doc As object
Dim wrdApp as object
snip
Set wrdApp = CreateObject("W ord.Application ")
Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge
..Destination = wdSendToNewDocu ment
..SuppressBlank Lines = True
With .DataSource
..FirstRecord = wdDefaultFirstR ecord
..LastRecord = wdDefaultLastRe cord
End With
If .State = wdMainAndDataSo urce Then .Execute
End With
wrdApp.Visible = True
snip
End Sub
*************** *************** *************** ************
it halts on
..Destination = wdSendToNewDocu ment
with wdSendToNewDocu ment highlighted and 'unknown variable'
Any ideas?
TIA, Mike MacSween 21 3951
wdSendToNewDocu ment
is defined in the Word olb.
If you don't have a reference to that library, you can't resolve this name.
If you do have a reference to the library, you can find the numeric value of
wdSendToNewDocu ment
and put that into your code. I see there are a couple more of these terms
from the Word olb you'll have to do the same with if you want to remove the
reference to the olb.
HTH
- Turtle
"Mike MacSween" <mi************ ******@btintern et.com> wrote in message
news:3f******** *************@p ubnews.gradwell .net... Had some trouble with Word automation. Sorted it, in the process thought I would try late binding. Some people reccomend it. So this: *************** *************** *************** ************ Public Sub MailMerge(strQu ery As String, strTemplate As String) snip Dim doc As Word.Document Dim wrdApp As Word.Applicatio n snip
Set wrdApp = New Word.Applicatio n Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge .Destination = wdSendToNewDocu ment .SuppressBlankL ines = True With .DataSource .FirstRecord = wdDefaultFirstR ecord .LastRecord = wdDefaultLastRe cord End With If .State = wdMainAndDataSo urce Then .Execute End With wrdApp.Visible = True snip End Sub *************** *************** *************** ************ works, with a reference to the Word olb
If i change it to: *************** *************** *************** ************ Public Sub MailMerge(strQu ery As String, strTemplate As String) snip Dim doc As object Dim wrdApp as object snip
Set wrdApp = CreateObject("W ord.Application ") Set doc = wrdApp.Document s.Add(strPath & strTemplate)
With doc.MailMerge .Destination = wdSendToNewDocu ment .SuppressBlankL ines = True With .DataSource .FirstRecord = wdDefaultFirstR ecord .LastRecord = wdDefaultLastRe cord End With If .State = wdMainAndDataSo urce Then .Execute End With wrdApp.Visible = True snip End Sub *************** *************** *************** ************ it halts on .Destination = wdSendToNewDocu ment with wdSendToNewDocu ment highlighted and 'unknown variable'
Any ideas?
TIA, Mike MacSween
Mike,
wdSendToNewDocu ment is a named constant or something like that. What
if you cheat and do something like
?wdSendToNewDoc ument
in the immediate window, get the number/value associated with this
variable and use that number instead? Does it work?
just a haphazard guess, so don't spend any more than 30 seconds
playing with it...
"MacDermott " <ma********@nos pam.com> wrote in message
news:WF******** **********@news read1.news.atl. earthlink.net.. . wdSendToNewDocu ment is defined in the Word olb. If you don't have a reference to that library, you can't resolve this
name. If you do have a reference to the library, you can find the numeric value
of wdSendToNewDocu ment and put that into your code. I see there are a couple more of these terms from the Word olb you'll have to do the same with if you want to remove
the reference to the olb.
Thanks Turtle, that worked perfectly. Though I don' really understand. If
using CreateObject() to use automation gives me access to the Word methods
and properties, why not the constants?
Not sure which way to swing on this now. There seems to be a conflict. All
the literature says 'use early binding unless there's a very good reason not
to' whereas a lot of people say use late binding. Some advise using early in
development (to get the intellisense etc.) then change to late for
distribution. But if I'm going to have to find constant values myself that
loses some advantage. And I read to always use late if using MDEs.
Whaddya think?
Cheers, Mike
"Pieter Linden" <pi********@hot mail.com> wrote in message
news:bf******** *************** ***@posting.goo gle.com... Mike,
wdSendToNewDocu ment is a named constant or something like that. What if you cheat and do something like
?wdSendToNewDoc ument
Thanks Pieter, that did it.
Cheers, Mike
"Mike MacSween" <mi************ ******@btintern et.com> wrote:
No idea as to why constants can't be used. That said someone stated that he didn't
have any problem leaving the constants in the Access app when he changed back to
early binding for some more programming.
So you could Const them at the top of a module anyhow. Not sure which way to swing on this now. There seems to be a conflict. All the literature says 'use early binding unless there's a very good reason not to' whereas a lot of people say use late binding. Some advise using early in development (to get the intellisense etc.) then change to late for distribution . But if I'm going to have to find constant values myself that loses some advantage. And I read to always use late if using MDEs.
To me the issue is "Could there be a different version of xxx to which you have a
reference?" If Outlook, Word, Excel, ... then that's a very good possibility even
if in one organization. For example, and this happened to me, the IT guy upgraded
his version of Outlook just to play with things. And it promptly broke the app which
automatically sent out emails via Outlook for him.
Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at http://www.granite.ab.ca/accsmstr.htm
"Mike MacSween" <mi************ ******@btintern et.com> wrote in
news:3f******** *************@p ubnews.gradwell .net: "MacDermott " <ma********@nos pam.com> wrote in message news:WF******** **********@news read1.news.atl. earthlink.net.. . wdSendToNewDocu ment is defined in the Word olb. If you don't have a reference to that library, you can't resolve this name. If you do have a reference to the library, you can find the numeric value
of wdSendToNewDocu ment and put that into your code. I see there are a couple more of these terms from the Word olb you'll have to do the same with if you want to remove the reference to the olb.
Thanks Turtle, that worked perfectly. Though I don' really understand. If using CreateObject() to use automation gives me access to the Word methods and properties, why not the constants?
Not sure which way to swing on this now. There seems to be a conflict. All the literature says 'use early binding unless there's a very good reason not to' whereas a lot of people say use late binding. Some advise using early in development (to get the intellisense etc.) then change to late for distribution. But if I'm going to have to find constant values myself that loses some advantage. And I read to always use late if using MDEs.
Whaddya think?
Cheers, Mike
The constants are contained in the type library, not in the object. And
late binding does not require a type library, it simply binds the object's
name to its Dispatch ID. It does this at run-time, so if there's a problem,
that's when it will arise. Many developers want to know about problems at
compile time and so, even if the claimed speed advantage of early binding
seems to be exaggerated, they prefer early.
A problem with MDEs is that references cannot be changed. Perhaps, that is
why late binding is recommended for MDEs. IMO MDEs are sound devices for
those who write entirely original and supremely valuable code. They are
also helpful for the paranoid and those whose experience is so limited that
they think that they have created something wonderful and unique. I am
paranoid only about the Fascist Right, Religious Fundamentalists , the New
York Yankees, the USA Olympic Committee and other such nefarious groups. So
I don't use MDEs. And I know that I am neither wonderful nor unique.
Consider my evil twin, Kyle ...
--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
"Lyle Fairfield" <Mi************ @Invalid.Com> wrote in message
news:Xn******** ***********@130 .133.1.4... The constants are contained in the type library, not in the object. And late binding does not require a type library, it simply binds the object's name to its Dispatch ID.
Got it (I think):
object.property = 1
but if you want you can refer to 1 by saying "wdNewDoc", but only if you use
our library, where we've enumerated the constants. Or something like that.
It does this at run-time, so if there's a problem, that's when it will arise. Many developers want to know about problems at compile time and so, even if the claimed speed advantage of early binding seems to be exaggerated, they prefer early.
Yes, I can see that. Many developers would include me. But of course I'd
also like to know that something that runs just fine here, won't fall to
bits when it goes onto a client's machine, just because they have build
version 9.34.34.4334 of MS OfficeProduct, which is one build later than
mine. Does location make a difference? For instance I always install Office
into C:\Office XXX, with having so many different versions, whereas clients
will usually/often have the default of c:\program files\etc.
I can see the advantages of develop early, deploy late. (Does that sound
like some sort of new 'developement paradigm')
A problem with MDEs is that references cannot be changed. Perhaps, that is why late binding is recommended for MDEs.
I just like the idea of stopping people tinkering! That's my job.
IMO MDEs are sound devices for those who write entirely original and supremely valuable code.
See, you've been looking at my code again. If compiled to an MDE!
They are also helpful for the paranoid and those whose experience is so limited
that they think that they have created something wonderful and unique. I am paranoid only about the Fascist Right, Religious Fundamentalists , the New York Yankees, the USA Olympic Committee and other such nefarious groups.
Don't know about 3 and 4, they're in the American Colonies, yes? I know what
you mean about 1 and 2 though.
Mike
Here's another way of thinking of it:
Access doesn't know that you're making wrd into a Word object until
CreateObject is executed -
long after compile time, when it's trying to resolve constants, and
notices it doesn't know what wdSendToNewDocu ment means.
(Actually, as one poster comments, it doesn't even recognize the
constant after the object has been created, because the definition is in the
type library, not the object library.)
Personally, in such cases I like the solution of declaring constants at the
top of your module.
HTH
- Turtle
"Mike MacSween" <mi************ ******@btintern et.com> wrote in message
news:3f******** *************@p ubnews.gradwell .net... "MacDermott " <ma********@nos pam.com> wrote in message news:WF******** **********@news read1.news.atl. earthlink.net.. . wdSendToNewDocu ment is defined in the Word olb. If you don't have a reference to that library, you can't resolve this name. If you do have a reference to the library, you can find the numeric
value of wdSendToNewDocu ment and put that into your code. I see there are a couple more of these
terms from the Word olb you'll have to do the same with if you want to remove
the reference to the olb.
Thanks Turtle, that worked perfectly. Though I don' really understand. If using CreateObject() to use automation gives me access to the Word methods and properties, why not the constants?
Not sure which way to swing on this now. There seems to be a conflict. All the literature says 'use early binding unless there's a very good reason
not to' whereas a lot of people say use late binding. Some advise using early
in development (to get the intellisense etc.) then change to late for distribution. But if I'm going to have to find constant values myself that loses some advantage. And I read to always use late if using MDEs.
Whaddya think?
Cheers, Mike
"MacDermott " <ma********@nos pam.com> wrote in message
news:2K******** **********@news read2.news.atl. earthlink.net.. . Here's another way of thinking of it: Access doesn't know that you're making wrd into a Word object until CreateObject is executed - long after compile time, when it's trying to resolve constants,
and notices it doesn't know what wdSendToNewDocu ment means. (Actually, as one poster comments, it doesn't even recognize the constant after the object has been created, because the definition is in
the type library, not the object library.)
Yes, I understand
Personally, in such cases I like the solution of declaring constants at
the top of your module.
I just worked that out. I guess a strategy would be to start with early
binding (nice intellisense), compile (nice type checking), then remove the
reference. Then compile and each time it chokes change first the early
binding declaration and then each constant as it chokes on them one by one.
Thanks for your help.
Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JD Kronicz |
last post by:
Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right version of the MS Graph type
library. Up until now I have been walking them through
the process of setting the references to include their
version of MS Graph library.
My problem is that I can not seem to get the syntax
correct .. or perhaps...
|
by: Zlatko Matić |
last post by:
I was reading about late binding, but I'm not completely sure what is to be
done in order to adjust code to late binding...
For example, I'm not sure if this is correct:
early binding:
Dim ws As DAO.Workspace
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
|
by: eBob.com |
last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been
wanting this capability for a long time. But it seems that I cannot
use it with Option Strict On. In an event handler I have ...
Private Sub chkbxSelI_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
MsgBox("bingo for number " & sender.Tag.ToString)
End Sub
|
by: lgbjr |
last post by:
hi All,
I've decided to use Options Strict ON in one of my apps and now I'm trying
to fix a late binding issue. I have 5 integer arrays:
dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as integer
The integers in these arrays are actually pointers to different columns of
data in a text file.
|
by: Tim Roberts |
last post by:
I've been doing COM a long time, but I've just come across a behavior
with late binding that surprises me. VB and VBS are not my normal
milieux, so I'm hoping someone can point me to a document that
describes this.
Here's the setup. We have a COM server, written in Python. For
completeness, here is the script:
----- testserver.py -----
import pythoncom
| |
by: ManningFan |
last post by:
I need to use late binding in a project because it's company standard
to not include references which aren't MS defaults, so I can't add the
scripting runtime.
I need to be able to search folders (and sub-forders) for a file name,
and then copy the file to a specified directory (at the moment it's
C:\TempCD but that will change later.
All I have so far is the following, I believe my main issue to tackle
is to figure out how to get to...
|
by: ADezii |
last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile time (Early Binding) or run time (Late Binding). When you declare an Object Variable as a specific Data Type, you are using Early Binding so the verification can take place during compile time. When you declare a Variable of the generic Object Data...
|
by: Siv |
last post by:
hi,
I am converting an application that writes to an Excel spreadsheet and the
code trips the "option Strict" that I would like on because the parser says
"option Strict On disallows late binding", I am struggling to understand why
I am tripping this error.
This is the code that causes the problems:
XLApp.Goto("MonthTitleTL") 'Goes to bookmark in sheet
r = XLApp.ActiveCell.Row 'sets variable r equal
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |