473,656 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Query with User-defined function?

Hello All,
In an 'Update' query can you use user-defined functions in the 'Update
To' for the query? Either no or I'm missing something. See the
additional info below.
If I run a query as a select query it runs fine. The select query is as
follows:

SELECT tblOrderPrYr_Se tup.ID,
RtnRndEstRevPY( tblOrderPrYr_Se tup!EstRev,tblO rderPrYr_Setup! ID)
AS RevisedRev,
RtnRndEstRevPY([tblOrderPrYr_Se tup]![EstCGS],[tblOrderPrYr_Se tup]![ID])
AS RevisedCGS
FROM tblOrderPrYr_Se tup;
If I change it to an update query on and either try to run it, save it,
or open into SQL I get an error message which reads:

'RtnRndEstRevPY ([tblOrderPrYr_Se tup]![EstCGS],[tblOrderPrYr_Se tup]![ID])'
is not a valid name. Make sure that it does not include any invalid
characters or punctuation and that it is not too long.

The custom function is as follows:

Function RtnRndEstRevPY( dblEstRevPY As Variant, lngID As Variant)
'Randomize 'initialize random number generator
dblEstRevPY = Round(dblEstRev PY * ((0.94 - 0.9) * Rnd(lngID) + 0.9),
0)
RtnRndEstRevPY = dblEstRevPY
End Function
I originally had dblEstRevPY as a double and lngID as a long integer,
but I have changed them to variant. Still same error. It appears Access
does not see that I'm calling the 2 expressions RevisedRev and
RevisedCGS, respectively, when I change it to an update query.

Thanks!

--
Regards,

Greg Strong
Nov 13 '05 #1
6 7894
Normally you'd use periods, not exclamation points, in SQL. Try switching
and see if that helps.

"Greg Strong" <NoJunk@NoJunk4 U².com> wrote in message
news:5p******** *************** *********@4ax.c om...
Hello All,
In an 'Update' query can you use user-defined functions in the 'Update
To' for the query? Either no or I'm missing something. See the
additional info below.
If I run a query as a select query it runs fine. The select query is as
follows:

SELECT tblOrderPrYr_Se tup.ID,
RtnRndEstRevPY( tblOrderPrYr_Se tup!EstRev,tblO rderPrYr_Setup! ID)
AS RevisedRev,
RtnRndEstRevPY([tblOrderPrYr_Se tup]![EstCGS],[tblOrderPrYr_Se tup]![ID])
AS RevisedCGS
FROM tblOrderPrYr_Se tup;
If I change it to an update query on and either try to run it, save it,
or open into SQL I get an error message which reads:

'RtnRndEstRevPY ([tblOrderPrYr_Se tup]![EstCGS],[tblOrderPrYr_Se tup]![ID])'
is not a valid name. Make sure that it does not include any invalid
characters or punctuation and that it is not too long.

The custom function is as follows:

Function RtnRndEstRevPY( dblEstRevPY As Variant, lngID As Variant)
'Randomize 'initialize random number generator
dblEstRevPY = Round(dblEstRev PY * ((0.94 - 0.9) * Rnd(lngID) + 0.9),
0)
RtnRndEstRevPY = dblEstRevPY
End Function
I originally had dblEstRevPY as a double and lngID as a long integer,
but I have changed them to variant. Still same error. It appears Access
does not see that I'm calling the 2 expressions RevisedRev and
RevisedCGS, respectively, when I change it to an update query.

Thanks!

--
Regards,

Greg Strong

Nov 13 '05 #2
Hi Greg,

You certainly can use functions in the Update To of a query.

The standard syntax for referring to a field in a tables is using a
period instead of !:
tblOrderPrYr_Se tup.EstRev
I don't know if this is the source of your problem.

Actually, in this case, since you only have one table in your From
clause, you don't need to refer to the table:
RtnRndEstRevPY( EstRev,ID).

If these changes don't help, I suggest you pare your query down to the
simplest components that demonstrate your problem, and then post the
SQL of the update query.

Jerry

Nov 13 '05 #3
On Fri, 30 Sep 2005 09:55:35 -0700, "Bruce Rusk"
<br************ ***@stanford.ed oo> wrote:
Normally you'd use periods, not exclamation points, in SQL. Try switching
and see if that helps.


No. I tried replacing "!" with "." and also removing the brackets in
Access's GUI query builder. After I leave the field Access puts the
brackets back, and I get the same error message except the exclamation
points are replaced with the periods. Thanks for the suggestion.

--
Regards,

Greg Strong
Nov 13 '05 #4
You could try:

(a) to write the update query from scratch in SQL

or

(B)

- Write a simpler select query, with the same fields but without the
function (e.g., instead of the function just add or concatenate the two
fields)

- Change that simpler query to an update

- Add the function to the resulting Update query

Also, it's a good idea to specify that your function returns a long (or
other data type).

"Greg Strong" <NoJunk@NoJunk4 U².com> wrote in message
news:eu******** *************** *********@4ax.c om...
On Fri, 30 Sep 2005 09:55:35 -0700, "Bruce Rusk"
<br************ ***@stanford.ed oo> wrote:
Normally you'd use periods, not exclamation points, in SQL. Try switching
and see if that helps.


No. I tried replacing "!" with "." and also removing the brackets in
Access's GUI query builder. After I leave the field Access puts the
brackets back, and I get the same error message except the exclamation
points are replaced with the periods. Thanks for the suggestion.

--
Regards,

Greg Strong

Nov 13 '05 #5
Specifically what field are you trying to Update?

Nov 13 '05 #6
On Fri, 30 Sep 2005 10:48:18 -0700, "Bruce Rusk"
<br************ ***@stanford.ed oo> wrote:
- Write a simpler select query, with the same fields but without the
function (e.g., instead of the function just add or concatenate the two
fields)

- Change that simpler query to an update

- Add the function to the resulting Update query

Also, it's a good idea to specify that your function returns a long (or
other data type).


This approach help fix the problem. I also changed the function back to
the original using a double and long variables to pass. Solution was:

SQL update query:
UPDATE tblOrderPrYr_Se tup SET tblOrderPrYr_Se tup.EstRev =
RtnRndEstRevPY( tblOrderPrYr_Se tup.EstRev,tblO rderPrYr_Setup. ID),
tblOrderPrYr_Se tup.EstCGS =
RtnRndEstRevPY( tblOrderPrYr_Se tup.EstCGS,tblO rderPrYr_Setup. ID);

User-defined function:
Function RtnRndEstRevPY( dblEstRevPY As Double, lngID As Double)
'Randomize 'initialize random number generator
dblEstRevPY = Round(dblEstRev PY * ((0.94 - 0.9) * Rnd(lngID) + 0.9),
0)
RtnRndEstRevPY = dblEstRevPY
End Function
Thanks for the help!

--
Regards,

Greg Strong
Nov 13 '05 #7

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

Similar topics

1
5176
by: Kunal | last post by:
Hi, I need some help on writing an update query to update "UnitsSold" field in Products Table whenever I save a transaction. The transaction may contain several "Subtransactions", one for each product sold in that transaction. I have a subtransaction table that maintains record of each subtransaction, with data such as: ProductID, Quantity, TransactionID etc. The Products table has fields: ProductID, UnitsSold, UnitsOrdered,...
0
449
by: ghadley_00 | last post by:
Run Update Query in silently in background I have a MS access 200 DB in which I have an update query which repalces all the " " with ''" in a field. I would like the update query to run in the background, and not ask the user for any perrmissions. I was thinking to run the query as part of the autoexec macro. can anyone recommend a way that I can have the update query run in the background? I don't see an obvious way to set the...
15
3292
by: Darren | last post by:
Help, i want to run an update query from a form.. and was wonderin.. Can the update query run if i want to update a value manually inputted from a form (e.g. !!) to a table (tblPasswordMgmt.Password) but based on a criteria which is neither the two values. Instead it's like (!!=tblPasswordMgmt.UserID).
0
1282
by: DP | last post by:
hi, i;ve created an update query, which WORKS!!, i've got an update to check a checkbox in a film table, and i've got another update query to uncheck a checkbox, when a record is deleted. but when i go to delete the record, it asks me if i want to run the update query, then stops and says;
4
412
by: jofo | last post by:
Hello all, I have project form and an hours form and related tables for each. The project table has a status flag to determine if the project is open or closed. When a user enters hours on a separate form, they can click a check box saying that the project is complete. When the user clicks the add record command button, I would like to do an Update query on the project table if the project is marked as complete.
3
2173
by: rdraider | last post by:
Hi all, Any thoughts on the best way to run an update query to update a specific list of records where all records get updated to same thing. I would think a temp table to hold the list would be best but am also looking at the easiest for an end user to run. The list of items is over 7000 Example: update imitmidx_sql set activity_cd = 'O', activity_dt = '20060601', prod_cat = 'OBS' where item_no = '001-LBK' update imitmidx_sql set...
1
3203
by: hmlarson | last post by:
I have a form/table with checkboxes that I would like the user to check / uncheck if they want a certain record to display in a gallery on a website. I'm having problems figuring out how to construct the update query so that it picks up when a user checks/unchecks the checkbox and updates the db w/ the matching record ID#. Right now, if a user unchecks a box, the value does not get passed and the DB does not update - set/change it to...
2
2344
by: eggie5 | last post by:
I have some code (C#) that runs an SQL update query that sets the value of a column to what the user passes. So, this causes an error when anything the user passes in has a ' character in it. I'm sure there's other characters that'll break it too. So, I was wondering, how do I get around this? Is there some commonly accepted regex pattern that will make the value safe to run in an SQL query? How can I take care of any values that need to...
12
1864
by: praveenkrg | last post by:
my update query is not working properly! $mgroupname=$_GET; //echo $mgroupname; ///query for checking userg_id $result=mysql_query("SELECT * FROM group WHERE userg_name ='$mgroupname'"); while($row = @mysql_fetch_array($result, MYSQL_ASSOC)) { $userg_id=$row;
3
2072
by: Erik Pygott | last post by:
I'm trying to make a query in Access 2007 to append a record in one table to another table and include a bit of user-supplied information. Let's say there are two tables: TableA and TableB. TableA looks like: TableB looks like: TermTicket is supplied by the user, ID is taken from the form for the specific record Right now I have an append query to copy the table info then an update query to add in the TermTicket. Is there any way to...
0
8297
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
8816
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
8717
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
8600
tracyyun
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...
0
5629
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
4150
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...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
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.