Hi!
A button on frmOrders will let user return an order. But...
The following SQL is giving me a headache:
strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _
& "SELECT Amount,MyDate,Returned " _
& "FROM tblOrderdetails " _
& "WHERE tblOrderdetails.Returned = True
AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID
AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID;"
CurrentDb.Execute strPutBack, dbFailOnError
I have a similar construct in another button and it works just nice.
The error message I get is:
Error: #3061 Too few parameters. Expected 2
Now, if I change the last query filter to:
....AND tblOrderdetails.OrderID = " & Me!OrderID
I get: Error: #3061 Too few parameters. Expected 1
Can anyone see what obviously I don't?
Me.Name
Geir Smevig-Baardsen
MCP http://www.geirb.info
*******************
*Don't reply to my
*email.
*Reply to group
*:-)
*
*
******************* 12 1589
Concatenate the values from the text boxes into the string:
strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _
& "SELECT Amount,MyDate,Returned " _
& "FROM tblOrderdetails " _
& "WHERE (tblOrderdetails.Returned = True) " _
& ") AND (tblOrderdetails.ItemID = " &
Forms!frmOrders!frmOrderdetails!ItemID _
& ") AND (tblOrderdetails.OrderID = " & Forms!frmOrders!OrderID & ");"
Extra quotes needed if the fields are Text type.
Won't work correctly if the fields are null.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Krij" <gs***@start.no> wrote in message
news:11**********************@b68g2000cwa.googlegr oups.com... A button on frmOrders will let user return an order. But...
The following SQL is giving me a headache:
strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _ & "SELECT Amount,MyDate,Returned " _ & "FROM tblOrderdetails " _ & "WHERE tblOrderdetails.Returned = True AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID;"
CurrentDb.Execute strPutBack, dbFailOnError
I have a similar construct in another button and it works just nice.
The error message I get is:
Error: #3061 Too few parameters. Expected 2
Now, if I change the last query filter to:
...AND tblOrderdetails.OrderID = " & Me!OrderID
I get: Error: #3061 Too few parameters. Expected 1
Can anyone see what obviously I don't?
Allen Browne <Al*********@SeeSig.Invalid> wrote:
: Concatenate the values from the text boxes into the string:
: strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _
: & "SELECT Amount,MyDate,Returned " _
: & "FROM tblOrderdetails " _
: & "WHERE (tblOrderdetails.Returned = True) " _
: & ") AND (tblOrderdetails.ItemID = " &
/\
|| I think that this is one parenthesis too many.
--thelma
---------------------------------------------
: Allen Browne - Microsoft MVP. Perth, Western Australia.
: Tips for Access users - http://allenbrowne.com/tips.html
: Reply to group, rather than allenbrowne at mvps dot org.
Hi!
Sorry...I made a mistake in pasting code. There are no parenthesis.
There are no textboxes. 'Amount' is an integer, 'MyDate' is Date/Time
and 'Returned' is a Yes/No field.
The fields are identical in both tables.
I was wondering....I'm running this ms access db 2000 on a machine with
Win XP Pro installed and Office XP. Could this be an issue?
I've had some other pecularities, so maybe others have had any
experience with this configuration?
Any suggestion to #Error 3061?
Thelma Lubkin skrev: Allen Browne <Al*********@SeeSig.Invalid> wrote: : Concatenate the values from the text boxes into the string:
: strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _ : & "SELECT Amount,MyDate,Returned " _ : & "FROM tblOrderdetails " _ : & "WHERE (tblOrderdetails.Returned = True) " _ : & ") AND (tblOrderdetails.ItemID = " & /\ || I think that this is one parenthesis too many. --thelma ---------------------------------------------
: Allen Browne - Microsoft MVP. Perth, Western Australia. : Tips for Access users - http://allenbrowne.com/tips.html : Reply to group, rather than allenbrowne at mvps dot org.
There is not problem with your setup. The issue is that the Expression
Service (ES) evaluates the 2 parameters (the values in the text boxes on the
form) when you run the query from the query window, but Access does not
invoke the ES with the Execute method.
The simple solution is concatenate the actual values into the string.
The data type of the 3 fields does not matter. It is the ItemID and OrderID
that matters: these are the 2 fields receiving values from the text boxes in
the WHERE clause.
Error 3061 indicates that there is a name in the query that does not resolve
to a table/field name. In your case, the 2 names that it cannot identify as
table/field names are:
Forms!frmOrders!frmOrderdetails!ItemID
Forms!frmOrders!OrderID
This is because the ES is not available in the context of the Execute method
to tell Access how to read the values from the form.
Thanks, Thelma. There was an extra bracket.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Krij" <gs***@start.no> wrote in message
news:11*********************@r2g2000cwb.googlegrou ps.com... Hi!
Sorry...I made a mistake in pasting code. There are no parenthesis. There are no textboxes. 'Amount' is an integer, 'MyDate' is Date/Time and 'Returned' is a Yes/No field.
The fields are identical in both tables.
I was wondering....I'm running this ms access db 2000 on a machine with Win XP Pro installed and Office XP. Could this be an issue?
I've had some other pecularities, so maybe others have had any experience with this configuration?
Any suggestion to #Error 3061?
Thelma Lubkin skrev:
Allen Browne <Al*********@SeeSig.Invalid> wrote: : Concatenate the values from the text boxes into the string:
: strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _ : & "SELECT Amount,MyDate,Returned " _ : & "FROM tblOrderdetails " _ : & "WHERE (tblOrderdetails.Returned = True) " _ : & ") AND (tblOrderdetails.ItemID = " & /\ || I think that this is one parenthesis too many. --thelma ---------------------------------------------
Krij wrote: strPutBack = "INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _ & "SELECT Amount,MyDate,Returned " _ & "FROM tblOrderdetails " _ & "WHERE tblOrderdetails.Returned = True AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID;"
I cannot understand why MS-Access continues to recommend such involved
syntax for refering to form values. Is frmOrderdetails a SubForm? In
that case, Forms!frmOrders!frmOrderdetails.Form.ItemID is required?
Regardless I never use such confusing code.
I ensure that each of my forms had the "HasModule" property set to True
(in older versions of Access it may be necessary to write a bit of code
for each form).
Then each property and control on the form can be referred to as
Form_FrmName.Property or Form_FrmName.Control whether the form is open
as main form or as subform (or open at all for that matter).
I would write (air) your code as
strPutBack = "INSERT INTO tblAmountItems " _
& "(Amount, MyDate, Returned) " _
& "SELECT Amount, MyDate, True " _
& "FROM tblOrderdetails " _
& "WHERE ItemID = " & Form_frmOrderdetails.ItemID.Value _
& " AND OrderID = " & OrderID.Value
Depending on circumstances I might modify the last two lines to
& "WHERE ItemID = " & Nz(Form_frmOrderdetails.ItemID.Value, 0) _
& " AND OrderID = " & Nz(OrderID.Value, 0)
I would also put a temporary break at this line (or right after) so
that I could see and evaluate strPutBack before using it.
If I were absolutely committed to doing things MS's convoluted, ugly
and inefficient way then I would try:
strPutBack = "INSERT INTO tblAmountItems " _
& "(Amount, MyDate, Returned) " _
& "SELECT Amount, MyDate, True " _
& "FROM tblOrderdetails " _
& "WHERE ItemID = " & Forms!frmOrders!frmOrderdetails.Form.ItemID _
& " AND OrderID = " & OrderID"
Lyle Fairfield <ly***********@aim.com> wrote:
: I would write (air) your code as
: strPutBack = "INSERT INTO tblAmountItems " _
: & "(Amount, MyDate, Returned) " _
: & "SELECT Amount, MyDate, True " _
: & "FROM tblOrderdetails " _
: & "WHERE ItemID = " & Form_frmOrderdetails.ItemID.Value _
: & " AND OrderID = " & OrderID.Value
I'm not sure how airy this statement was meant to be. Does
specifying what fields to insert into determine which fields
are selected--what would happen in this case if tblOrderdetails
had more than one Boolean field, since the statement as written
doesn't include "Returned = True" in its WHERE clause? Even if
there is only one, does it know enough to choose records with
the Boolean field true?
--thelma
Thelma Lubkin wrote: Lyle Fairfield <ly***********@aim.com> wrote: : I would write (air) your code as
: strPutBack = "INSERT INTO tblAmountItems " _ : & "(Amount, MyDate, Returned) " _ : & "SELECT Amount, MyDate, True " _ : & "FROM tblOrderdetails " _ : & "WHERE ItemID = " & Form_frmOrderdetails.ItemID.Value _ : & " AND OrderID = " & OrderID.Value
I'm not sure how airy this statement was meant to be. Does specifying what fields to insert into determine which fields are selected--what would happen in this case if tblOrderdetails had more than one Boolean field, since the statement as written doesn't include "Returned = True" in its WHERE clause? Even if there is only one, does it know enough to choose records with the Boolean field true?
--thelma
Airy enough to have omitted a line.
I conjectured from the nature of:
"INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _
& "SELECT Amount,MyDate,Returned " _
& "FROM tblOrderdetails " _
& "WHERE tblOrderdetails.Returned = True
AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID
AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID;"
that the field Returned in tblOrderdetails was being used only to
ensure that the inserted field Returned in tblAmountItems would be set
as True.
Clearly I was wrong. While I believe that it is unlikely, it certainly
may be that there are records in tblOrderdetails
WHERE Returned = False
AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID
AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID
and that the user/developer does not want these records inserted into
tbAmountItems.
So another airy attempt is:
strPutBack = "INSERT INTO tblAmountItems " _
& "(Amount, MyDate, Returned) " _
& "SELECT Amount, MyDate, True " _
& "FROM tblOrderdetails " _
& "WHERE Returned " _
& "AND ItemID = " & Form_frmOrderdetails.ItemID.Value _
& " AND OrderID = " & OrderID.Value
Thanks, for pointing this out.
Hi!
I would like to give a BIG thank you to all who has contributed with
suggestions and answers.
Not having tried yet, I'm sure I'll solve this by the help I've
received.
Have a nice day! :-)
Me.Name
Lyle Fairfield skrev: I conjectured from the nature of:
"INSERT INTO tblAmountItems(Amount,MyDate,Returned) " _ & "SELECT Amount,MyDate,Returned " _ & "FROM tblOrderdetails " _ & "WHERE tblOrderdetails.Returned = True AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID;"
that the field Returned in tblOrderdetails was being used only to ensure that the inserted field Returned in tblAmountItems would be set as True.
Clearly I was wrong. While I believe that it is unlikely, it certainly may be that there are records in tblOrderdetails WHERE Returned = False AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID
and that the user/developer does not want these records inserted into tbAmountItems.
So another airy attempt is:
strPutBack = "INSERT INTO tblAmountItems " _ & "(Amount, MyDate, Returned) " _ & "SELECT Amount, MyDate, True " _ & "FROM tblOrderdetails " _ & "WHERE Returned " _ & "AND ItemID = " & Form_frmOrderdetails.ItemID.Value _ & " AND OrderID = " & OrderID.Value
Thanks, for pointing this out.
Krij wrote: Lyle Fairfield skrev:
Dim ThelmaIsAbout as Boolean
If ThelmaIsAbout Then
Be Careful with Your Skreving
End If
Hi!
I solved the problem anyway with the help I received. :-)
Skreving? A new english word or...??????
Lyle Fairfield skrev: Krij wrote:
Lyle Fairfield skrev:
Dim ThelmaIsAbout as Boolean
If ThelmaIsAbout Then Be Careful with Your Skreving End If
Hi!
The problem with this SQL statement is that it doesn't 'know' which
record to put into.
Therefore:
strPutBack = "INSERT INTO
tblAmountItems(ItemID,Amount,MyDate,Returned) " _
& "SELECT ItemID,Amount,MyDate,Returned " _
& "FROM tblOrderdetails " _
& "WHERE tblOrderdetails.Returned = True
AND tblOrderdetails.ItemID = Forms!frmOrders!frmOrderdetails!ItemID
AND tblOrderdetails.OrderID = Forms!frmOrders!OrderID;"
CurrentDb.Execute strPutBack, dbFailOnError
Now as the ItemID has been identified, it'll work OK :-)
Me.Name
Krij skrev: Hi!
I solved the problem anyway with the help I received. :-)
Skreving? A new english word or...??????
Lyle Fairfield skrev:
Krij wrote:
Lyle Fairfield skrev:
Dim ThelmaIsAbout as Boolean
If ThelmaIsAbout Then Be Careful with Your Skreving End If This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: David |
last post by:
On every web browser except Safari, this website works great. (Well,
by "every" I mean Mozilla, Netscape, and Internet Explorer, for Mac
and Windows).
The site is: http://www.ruleofthirds.com
...
|
by: Ryan Ternier |
last post by:
I'm having an issue with an SQL insert statement. It's a very simple
statement, and it's causing too much fuss.
strSQL = "INSERT INTO tblFieldLayouts(TypeID, FieldID, OrderID, Hidden)
VALUES("...
|
by: laurenq uantrell |
last post by:
I'm trying to return an integer from the following table that returns
the number of unique cities:
tblEmployees
Name City
John Boston
Frank New York
Jim Omaha
Betty ...
|
by: NuB |
last post by:
The validation controls are giving me a headache. here is what i'm trying to
do and so far what I've tried has not worked.
I need to hide my grid if the page is not valid
how can i accomplish...
|
by: James Ma |
last post by:
Now I am debugging a buggy VB.NET function like following
Function foo()
Try
‘ many loops and codes and nested try catch here!
……
Catch (ex as Exception)
Msgbox ex.message
Finally
…
|
by: Echo |
last post by:
Hi all. Sorry about the crude headline but this problem is really
giving me a headache. See I am currently deloping an app in Visual
Studios 2005 C# Lanuage and the thing is like this: I have a...
|
by: gchq |
last post by:
Hi there
Attempting to populate a dynamic table with data - that in itself is not a problem, but getting group headers IS giving me a headache. Know I've done this before, but can I remember how?...
|
by: plemon |
last post by:
this script was working now ive added to it and its no longer my
friend.
here is the very first one
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
|
by: pandaking |
last post by:
Hi there everyone, new here but after reading around it seems like I might hang about - so many helpful threads!
I have a slight problem. This flying club near me has employed me to make them a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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: 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,...
| |