473,769 Members | 5,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass a Parameter to a Query in Access Front-End

I thought would be a super simple project, but I was wrong. I need
Help!!!!

I am using the Word.Applicatio n.Mailmerge.Ope nDataSource to try and
send a Dynamic Query to my stated Document.Open File. For the life of
me I cannot fiqure out how to pass a parameter from this code to the
"Proposal" Query in the Access Front End. If I do not add the param
variable then everthing works fine except that it pulls all of the
matching records instead of the specific one based on the proposal
number. I am open to any Suggestions.
SEE CODE BELOW:
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
Dim strSQL As String
Dim param As Integer
Set oApp = CreateObject("W ord.Application ")

Set Db = CurrentDb
Set oMainDoc = oApp.Documents. Open("c:\MARK\p roposal.doc")
With oMainDoc.MailMe rge

.MainDocumentTy pe = wdFormLetters

param = Me![ProposalNumber]
strSQL = "Proposal" & param
.OpenDataSource Name:=Db, SQLStatement:=s trSQL
End With
With oMainDoc
.MailMerge.Dest ination = wdSendToNewDocu ment
.MailMerge.Exec ute Pause:=False
.Close False
End With
oApp.Visible = True
Nov 12 '05 #1
3 2354
"Mark Horton" <mh*****@texasp ension.com> wrote in message
news:dc******** *************** ***@posting.goo gle.com...
I thought would be a super simple project, but I was wrong. I need
Help!!!!

I am using the Word.Applicatio n.Mailmerge.Ope nDataSource to try and
send a Dynamic Query to my stated Document.Open File. For the life of
me I cannot fiqure out how to pass a parameter from this code to the
"Proposal" Query in the Access Front End. If I do not add the param
variable then everthing works fine except that it pulls all of the
matching records instead of the specific one based on the proposal
number. I am open to any Suggestions.
SEE CODE BELOW:
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
Dim strSQL As String
Dim param As Integer
Set oApp = CreateObject("W ord.Application ")

Set Db = CurrentDb
Set oMainDoc = oApp.Documents. Open("c:\MARK\p roposal.doc")
With oMainDoc.MailMe rge

.MainDocumentTy pe = wdFormLetters

param = Me![ProposalNumber]
strSQL = "Proposal" & param
.OpenDataSource Name:=Db, SQLStatement:=s trSQL
End With
With oMainDoc
.MailMerge.Dest ination = wdSendToNewDocu ment
.MailMerge.Exec ute Pause:=False
.Close False
End With
oApp.Visible = True


There are a number of things I'm puzzled with here. Firstly, it looks like
you have elected for late-binding with the line:
Set oApp = CreateObject("W ord.Application ")
But a few lines down, it looks like you have placed a reference to the Word
library and using its constants:
.MailMerge.Dest ination = wdSendToNewDocu ment

Are you aware of the pros and cons of early / late binding and have you made
a conscious choice?
Secondly, I'm not sure what this is:
strSQL = "Proposal" & param

Is "Proposal" the name of a query? Using a naming convention where you
called it "qryProposa l" would help others understand if that was the case.
One possible way would be to create a query "qrySelectedPro posal" which you
re-write at run-time to get the result you want (see function below), but at
a guess, your query is supposed to only return one record anyway and so
perhaps an actual mail-merge is not the best way. You could do other things
in code beside mailmerge.
Public Function DefineQuery(str QueryName As String, strSQL As String) As
Boolean

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb

Set qdf = dbs.QueryDefs(s trQueryName)

qdf.SQL = strSQL

DefineQuery = True

Exit_Handler:
If Not qdf Is Nothing Then Set qdf = Nothing
If Not dbs Is Nothing Then Set dbs = Nothing
Exit Function

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
Nov 12 '05 #2

Thanks for the Help. I fixed the late binding mistake, it was not a
intentional coding choice. I am sorry for my ignorance, but you said:
"You could do other things
in code beside mailmerge." What other things would be better to pass a
query to a Word Document besides using mailmerge?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
"Mark Horton" <mh*****@texasp ension.com> wrote in message
news:40******** *************@n ews.frii.net...

Thanks for the Help. I fixed the late binding mistake, it was not a
intentional coding choice. I am sorry for my ignorance, but you said:
"You could do other things
in code beside mailmerge." What other things would be better to pass a
query to a Word Document besides using mailmerge?


Hi Mark

Well if it's only one document, you could have open a standard Word document
or template (no mailmerge data) and replace certain key terms with
information from the database.
One advantage is that your users need zero mailmerge skills to alter or
create new documents. In the example below, the code replaces the
text[[ProposalNumber]] with the value from the current record.

strPropNo = Cstr(Nz(Me!Prop osalNumber, 0))
Set WdDoc = WdApp.Documents .Add(strTemplat ePath)
Set WdRange = WdApp.ActiveDoc ument.Content
WdRange.Find.Ex ecute FindText:="[[ProposalNumber]]", ReplaceWith:=st rPropNo,
Replace:=wdRepl aceAll
Fletcher
Nov 12 '05 #4

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

Similar topics

5
14043
by: Belinda | last post by:
Hello All I have the following test.asp page which needs one parameter querystr but my querystr is a very long string value. When I send a long value the query string is getting truncated after some characters. Can you please kindly share the code segment to workaround how to pass such a long string value to a asp page. This is how I invoke the test page:
5
13224
by: Don Seckler | last post by:
I have an update query that runs when a report closes. I have several reports that will need to run the update query with diferent criteria. I'd like to simply make the criteria change in the report vba instead of making different queries. Here's my query sql: UPDATE Draw SET Draw.Billed = Yes WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)="Hudson"));
3
2727
by: Paradigm | last post by:
I want to create a pass through query in Access to get data from a MYSQL table. I need to do this using code so that certain aspects of the query can be changed. When I look at the SQL version of a Select and a Passthrough query in access they appear to be the same. eg. "SELECT * FROM MYTABLE WHERE MYFIELD = TRUE" What do I need to do to make this a pass through query? Any help appreciated. Alex
2
30336
by: rg | last post by:
Hi all, I have query about passing a parameter from form to a query. My situation is as follows: I have a query that pulls up some data from a table, however there is a condition that must be filled in by the user. Hence when you run the query there is a "Enter Parameter Value" prompt that must be completed. A further complication is that the parameter is actually within the WHERE statement, i.e.:
1
7758
by: | last post by:
Hi, I've defined an ObjectDataSource and a parameterized DataSet. I would like it if I could pass the parameter value that describes the query that creates the DataSet as part of a user control declaration. Here's how the parameter is described in the context of my ObjectDataSource: <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetArticlesByWhomever" TypeName="WhateverTableAdapters.WhateverTableAdapter">
2
6375
by: Roger | last post by:
Anyone know how to pass a parameter to a query via a report in Access 2003?
2
20457
by: Dud Bug | last post by:
I have a query in an Access db that prompts the user for info. (e.g. a primary key representing a company) before compiling the relevant table of results. This works fine in Access but I want to use this query from within VB.Net. But how do I, in code, pass a parameter to the Access query?
1
17313
by: woody | last post by:
I have a bit of a newbie question (basically stated in the subject of the posting). If need to get some data out of a SQL Server Database. Can I use a control from a form to supply a parameter. I've created a stored procedure with the parameter I need, I just dont know how to send the data from the form to the SPT query. So I need to get data out of !! to my SPT query. Can I do it? Any help is greatly appreciated.
1
7514
by: lesmccoy | last post by:
Hi I am using the openrecordet in the Ms Access to open saved queries I have in my database. I am trying to pass a parameter into the openrecordset the query has to use. For example the query is a list of info for machine for two users and I want to open the saved query and pass in parameter to only show one of the users info. I am using the following code. dim dbs as database
22
11345
by: Lewe22 | last post by:
I am creating a small Access db which performs a series of updates to a SQL database. The Access db consists of a ‘Main Form’, from which the user can run each update via a series of command buttons. Each update has been written as a SQL pass-through query. Example Update: UPDATE unit_instance_occurrences uio SET fes_active_places =
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
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...
0
8869
agi2029
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...
0
6668
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();...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
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
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.