473,386 Members | 1,715 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,386 software developers and data experts.

Can I pass a filter to an update query via vba

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"));
And My code that runs the update query

DoCmd.OpenQuery "DrawBillUpdateQueryHudson"

How do I pass the criteria : ((Draw.WholesalerName)="Hudson")); via
the VBA in the report?
Nov 12 '05 #1
5 13177
On 1 Apr 2004 12:04:05 -0800, dj*******@hotmail.com (Don Seckler)
wrote:
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"));
And My code that runs the update query

DoCmd.OpenQuery "DrawBillUpdateQueryHudson"

How do I pass the criteria : ((Draw.WholesalerName)="Hudson")); via
the VBA in the report?

Why not just simply execute an SQL string instead of using a saved
query?

Dim strUpDate As String

strUpDate = "UPDATE Draw SET Draw.Billed = Yes " _
& "WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)='Hudson'));"
'Note you need to use single quotes around text values

CurrentDb.Execute strUpDate, DbFailOnError

- Jim
Nov 12 '05 #2
Thanks Jim. I thought there was a more simple solution.
"Jim Allensworth" <ji****@Notdatacentricsolutions.com> wrote in message news:<40****************@news.west.earthlink.net>. ..
On 1 Apr 2004 12:04:05 -0800, dj*******@hotmail.com (Don Seckler)
wrote:
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"));
And My code that runs the update query

DoCmd.OpenQuery "DrawBillUpdateQueryHudson"

How do I pass the criteria : ((Draw.WholesalerName)="Hudson")); via
the VBA in the report?

Why not just simply execute an SQL string instead of using a saved
query?

Dim strUpDate As String

strUpDate = "UPDATE Draw SET Draw.Billed = Yes " _
& "WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)='Hudson'));"
'Note you need to use single quotes around text values

CurrentDb.Execute strUpDate, DbFailOnError

- Jim

Nov 12 '05 #3
Don

I'd do it Jim's way, but if you create a stored update query with a
parameter:[Name, or something] you can pass the parameter in code by
something like
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("name of query")
qdf![Name] = "name"
qdf.Execute
set qdf = nothing

Neil
dj*******@hotmail.com (Don Seckler) wrote in message news:<fe**************************@posting.google. com>...
Thanks Jim. I thought there was a more simple solution.
"Jim Allensworth" <ji****@Notdatacentricsolutions.com> wrote in message news:<40****************@news.west.earthlink.net>. ..
On 1 Apr 2004 12:04:05 -0800, dj*******@hotmail.com (Don Seckler)
wrote:
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"));
And My code that runs the update query

DoCmd.OpenQuery "DrawBillUpdateQueryHudson"

How do I pass the criteria : ((Draw.WholesalerName)="Hudson")); via
the VBA in the report?

Why not just simply execute an SQL string instead of using a saved
query?

Dim strUpDate As String

strUpDate = "UPDATE Draw SET Draw.Billed = Yes " _
& "WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)='Hudson'));"
'Note you need to use single quotes around text values

CurrentDb.Execute strUpDate, DbFailOnError

- Jim

Nov 12 '05 #4
Neil,

Watch out using Name, it is an Access reserved keyword.
If you want to go the querydef route, put a parameter in the
WholesalerName field -- [TheName]. Now run it like ....

-------------------------------------
Dim qdf As QueryDef

Set qdf = CurrentDb.QueryDefs("DrawBillUpdateQueryHudson")
With qdf
.Parameters("TheName") = Me.WholesalerName
.Execute
End With
Set qdf = Nothing
-------------------------------

This assumes you have a field in the form's recordset named
"WholesalerName"

- Jim

On 6 Apr 2004 07:48:10 -0700, ne***********@boroughmuir.edin.sch.uk
(NeilAnderson) wrote:
Don

I'd do it Jim's way, but if you create a stored update query with a
parameter:[Name, or something] you can pass the parameter in code by
something like
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("name of query")
qdf![Name] = "name"
qdf.Execute
set qdf = nothing

Neil
dj*******@hotmail.com (Don Seckler) wrote in message news:<fe**************************@posting.google. com>...
Thanks Jim. I thought there was a more simple solution.
"Jim Allensworth" <ji****@Notdatacentricsolutions.com> wrote in message news:<40****************@news.west.earthlink.net>. ..
> On 1 Apr 2004 12:04:05 -0800, dj*******@hotmail.com (Don Seckler)
> wrote:
>
> >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"));
> >
> >
> >And My code that runs the update query
> >
> >DoCmd.OpenQuery "DrawBillUpdateQueryHudson"
> >
> >How do I pass the criteria : ((Draw.WholesalerName)="Hudson")); via
> >the VBA in the report?
> Why not just simply execute an SQL string instead of using a saved
> query?
>
> Dim strUpDate As String
>
> strUpDate = "UPDATE Draw SET Draw.Billed = Yes " _
> & "WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)='Hudson'));"
> 'Note you need to use single quotes around text values
>
> CurrentDb.Execute strUpDate, DbFailOnError
>
> - Jim


Nov 12 '05 #5
Jim's way is right of course. I always do it in code because a) you
can trap errors, b) troubleshoot it more easily c) you might, like me,
have a tendancy to say "what's that query for? delete it" or d) change
the stored query without realizing what you are doing.

Neil

Ji****@NOTdatacentricsolutions.com (Jim Allensworth) wrote in message news:<40**************@netnews.comcast.net>...
Neil,

Watch out using Name, it is an Access reserved keyword.
If you want to go the querydef route, put a parameter in the
WholesalerName field -- [TheName]. Now run it like ....

-------------------------------------
Dim qdf As QueryDef

Set qdf = CurrentDb.QueryDefs("DrawBillUpdateQueryHudson")
With qdf
.Parameters("TheName") = Me.WholesalerName
.Execute
End With
Set qdf = Nothing
-------------------------------

This assumes you have a field in the form's recordset named
"WholesalerName"

- Jim

On 6 Apr 2004 07:48:10 -0700, ne***********@boroughmuir.edin.sch.uk
(NeilAnderson) wrote:
Don

I'd do it Jim's way, but if you create a stored update query with a
parameter:[Name, or something] you can pass the parameter in code by
something like
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("name of query")
qdf![Name] = "name"
qdf.Execute
set qdf = nothing

Neil
dj*******@hotmail.com (Don Seckler) wrote in message news:<fe**************************@posting.google. com>...
Thanks Jim. I thought there was a more simple solution.
"Jim Allensworth" <ji****@Notdatacentricsolutions.com> wrote in message news:<40****************@news.west.earthlink.net>. ..
> On 1 Apr 2004 12:04:05 -0800, dj*******@hotmail.com (Don Seckler)
> wrote:
>
> >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"));
> >
> >
> >And My code that runs the update query
> >
> >DoCmd.OpenQuery "DrawBillUpdateQueryHudson"
> >
> >How do I pass the criteria : ((Draw.WholesalerName)="Hudson")); via
> >the VBA in the report?
> Why not just simply execute an SQL string instead of using a saved
> query?
>
> Dim strUpDate As String
>
> strUpDate = "UPDATE Draw SET Draw.Billed = Yes " _
> & "WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)='Hudson'));"
> 'Note you need to use single quotes around text values
>
> CurrentDb.Execute strUpDate, DbFailOnError
>
> - Jim

Nov 12 '05 #6

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

Similar topics

5
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...
11
by: DFS | last post by:
Architecture: Access 2003 client, Oracle 9i repository, no Access security in place, ODBC linked tables. 100 or so users, in 3 or 4 groups (Oracle roles actually): Admins, Updaters and ReadOnly....
3
by: ILCSP | last post by:
Hello, I'm fairly new to the concept of running action pass through queries (insert, update, etc.) from Access 2000. I have a SQL Server 2000 database and I'm using a Access 2K database as my...
2
by: ILCSP | last post by:
Hello, I'm in the process of changing our 'normal' Access 2000 update queries to Update Pass Through Queries. We have a SQL server 2000 database and we're using an Access 2000 database as our...
0
by: Josetta | last post by:
This is for informational purposes...I had a problem and I thought it might help others in a similar situation. I hope someone, someday, finds this idea useful. I've garnered so much knowledge...
3
by: emgallagher | last post by:
I have a form which lists studies. People can filter the form based on details about the study, such as the study type. Currently users filter via the right click method. I would like to be...
1
by: lorirobn | last post by:
Hi, I have a list box on a form, whose row source points to a separate query. The query refers to a field on the form to filter records on the list box, like such: WHERE tblA.DesignType = !!...
22
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...
16
by: pabs1111 | last post by:
I'm trying to filter the records in a form using a pass through query. strFilter = strFilter & "( eventid in (select FWIPEvent.eventid from FWIPEvent )) " Me.Filter = strFilter Me.FilterOn =...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
0
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,...
0
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...
0
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,...
0
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...

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.