473,507 Members | 2,416 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A2K - simple append of one record to another table needed

Problem is that there are lots and lots of fields in an employee record. I
specify a form control as the criterion for one of those fields which is the
value of the primary key for that record. The idea is to copy the current
record I am viewing in the form, to another table.

I want to simple execute a stored query but I get a run-time error 3061, too
few parameters. Expected 1. So even though I've specified the control
within the query it's not finding the current control's value.

I don't want to cut and paste the string, mainly as I don't think it will
work - too long and all that and it would look a bit messy if I do get it
working.
Google groups is just saying that criteria should be specified but I can't
find anything else specific to my little problem.

Any way to fix my saved query?

thanks
Martin
Jan 16 '06 #1
2 2061
Solution 1
Concatenate the value into the SQL string in your code:
Dim strSql As String
strSql = "INSERT INTO ... WHERE ([SomeField] = " & _
Forms!Form1!Text0 & ");"
dbEngine(0)(0).Execute strSql, dbFailOnError

If SomeField is a Date/Time field, use # as the delimiter, and format the
date value:
strSql = "INSERT INTO ... WHERE ([SomeField] = #" & _
Format(Forms!Form1!Text0, "mm\/dd\/yyyy") & "#);"
If it is a Text type field, use " as the delimiter, doubled up (because
embedded in the string:
strSql = "INSERT INTO ... WHERE ([SomeField] = """ & _
Forms!Form1!Text0 & """);"

Solution 2:
If you prefer a saved query, explicitly supply the parameter:
Dim qdf As QueryDef
Set qdf = dbEngine(0)(0).QueryDefs("Query1")
qdf.Parameters("[Forms]![Form1]![Text0]") = [Forms]![Form1]![Text0]
qdf.Execute

Solution 3
Use RunSQL instead of Execute:
DoCmd.RunSQL "Query1"
Although simple, it has these disadvantages:
- Programmatically, you do not know if the insert succeeded.
- Confirmation dialog (can be suppressed by turning off SetWarnings.)

--
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.

"Deano" <de***@mailinator.com> wrote in message
news:43**********************@ptn-nntp-reader02.plus.net...
Problem is that there are lots and lots of fields in an employee record.
I
specify a form control as the criterion for one of those fields which is
the
value of the primary key for that record. The idea is to copy the current
record I am viewing in the form, to another table.

I want to simple execute a stored query but I get a run-time error 3061,
too
few parameters. Expected 1. So even though I've specified the control
within the query it's not finding the current control's value.

I don't want to cut and paste the string, mainly as I don't think it will
work - too long and all that and it would look a bit messy if I do get it
working.
Google groups is just saying that criteria should be specified but I can't
find anything else specific to my little problem.

Any way to fix my saved query?

thanks
Martin

Jan 16 '06 #2
Allen Browne wrote:
Solution 1
Concatenate the value into the SQL string in your code:
Dim strSql As String
strSql = "INSERT INTO ... WHERE ([SomeField] = " & _
Forms!Form1!Text0 & ");"
dbEngine(0)(0).Execute strSql, dbFailOnError

If SomeField is a Date/Time field, use # as the delimiter, and format
the date value:
strSql = "INSERT INTO ... WHERE ([SomeField] = #" & _
Format(Forms!Form1!Text0, "mm\/dd\/yyyy") & "#);"
If it is a Text type field, use " as the delimiter, doubled up
(because embedded in the string:
strSql = "INSERT INTO ... WHERE ([SomeField] = """ & _
Forms!Form1!Text0 & """);"

Solution 2:
If you prefer a saved query, explicitly supply the parameter:
Dim qdf As QueryDef
Set qdf = dbEngine(0)(0).QueryDefs("Query1")
qdf.Parameters("[Forms]![Form1]![Text0]") =
[Forms]![Form1]![Text0] qdf.Execute

Solution 3
Use RunSQL instead of Execute:
DoCmd.RunSQL "Query1"
Although simple, it has these disadvantages:
- Programmatically, you do not know if the insert succeeded.
- Confirmation dialog (can be suppressed by turning off SetWarnings.)


Thanks Allen, great post. I'm using Solution 2 successfully.
Jan 16 '06 #3

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

Similar topics

27
2341
by: Brian Sabbey | last post by:
Here is a first draft of a PEP for thunks. Please let me know what you think. If there is a positive response, I will create a real PEP. I made a patch that implements thunks as described here....
2
6527
by: Paul Wagstaff | last post by:
Hi there I have 2 tables: tblAccuracy & tblClearance Users add new records to tblAccuracy using frmRegister. Under specific conditions I need to append the current record from frmRegister into...
3
28829
by: Nhmiller | last post by:
I searched here for an answer. I am entering records into a database, and it would save a lot of time if I could duplicate a record that is very similar to the new one I am about to enter, then...
2
2368
by: Ray Holtz | last post by:
I have a form that shows a single record based on a query criteria. When I click a button it is set to use an append query to copy that record to a separate table, then deletes the record from the...
1
4282
by: travismorien | last post by:
I have four tables of different "entities". One table contains information for "people", one for "trusts", one for "companies" and one for "self managed super funds". Each type of entity has an...
22
18764
by: RayPower | last post by:
I'm having problem with using DAO recordset to append record into a table and subsequent code to update other tables in a transaction. The MDB is Access 2000 with the latest service pack of JET 4....
13
9810
by: technocraze | last post by:
Hi guys, I have an issue with incrementing a counter in a table using VB in MS Acess environment. Below mentioned is an instance. Implementation logic Table fields Serialno = pk Datatype...
8
1989
by: MLH | last post by:
I would like to modify the following SQL... INSERT INTO tblPmtsRcd (VehicleJobID, PmtAmt) SELECT GetCurrentVehicleJobID() AS MyVehicleJobID, !! AS MyPmtAmt; somehow so that an extra field in...
3
8023
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
0
7223
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
7319
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
5623
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,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
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...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
412
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...

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.