473,239 Members | 1,748 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,239 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 13156
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 =...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.