473,460 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Too few parameters error using Execute dbFailOnError

Hi there,
I am trying to insert 4 fields into a table grabbing the 4 fields from a form,
here is my code:
Private Sub LastPaymentAmount_AfterUpdate()

Dim CurrentProject As DAO.Database
Set CurrentProject = CurrentDB()

'CurrentProject.Execute "Insert into TransactionHistory values(FirstName,
LastName, LastPaymentDate, LastPaymentAmount)", dbFailOnError

End Sub

and I keep getting a too few parameters error on the Execute statement.
Also, I just pasted my code in, the Execute statement is actually all on one
line,
Thanks in advance for your help!
GM

Sep 3 '07 #1
4 2811
Per gmazza:
>'CurrentProject.Execute "Insert into TransactionHistory values(FirstName,
LastName, LastPaymentDate, LastPaymentAmount)", dbFailOnError
This is strictly a knee-jerk reaction... but it seems like the
query needs to know both the value tb inserted and the name of
the field the value goes into.

When I do something like that, it's more in the form of:

------------------------------------------------------------------
Private Sub cmdAdd_Click()
1000 debugStackPush Me.Name & ": cmdAdd_Click"
1001 On Error GoTo cmdAdd_Click_err

' PURPOSE: To add a new record to the table in question after
computing
' the next available CollateralManagerID
'
' NOTES: 1) FormOpen routine sets gModalAddDialogOutcome
semaphore=FALSE,
' we set it to TRUE to tell calling routine that
the add succeeded.

1002 Dim myQuery As DAO.QueryDef

Dim myUserID As String
Dim myNewRecordID As Long

1010 myUserID = CurrentUserGet()
1019 myNewRecordID = IdGetNext_CollateralManager()

1020 Set myQuery =
CurrentDb.QueryDefs("qryAddRec_CollateralManager")
1030 With myQuery
1031 .Parameters("theRecordID") = myNewRecordID
1032 .Parameters("theName") = Me.txtName
1033 .Parameters("theStreetAddress") = Me.txtStreetAddress
1034 .Parameters("theCity") = Me.txtCity
1035 .Parameters("theState") = Me.cboState
1039 .Parameters("theZip") = Me.txtZip
1040 .Parameters("theCountry") = Me.cboCountry
1041 .Parameters("theComments") = Me.txtComments
1042 .Parameters("theUserID") = myUserID
1043 .Parameters("theTimeStamp") = Now()
1044 .Execute dbFailOnError
1049 End With

1990 gModalDialogOutcome = True
1991 Me.Visible = False
1992 MsgBox "'" & Me.txtName & "' Added", 0, "Done!"
1999 DoCmd.Close acForm, Me.Name

cmdAdd_Click_xit:
DebugStackPop
On Error Resume Next
Set myQuery = Nothing
Exit Sub

cmdAdd_Click_err:
If Err = gError_DuplicateValue Then
MsgBox "That name already exists", 48, "Cannot Add Duplicate"
Else
BugAlert True, ""
End If
Resume cmdAdd_Click_xit
End Sub
------------------------------------------------------------------

Where qryAddRec_CollateralManager looks like this:
------------------------------------------------------------------
PARAMETERS
theName Text ( 255 ),
theStreetAddress Text ( 255 ),
theCity Text ( 255 ),
theState Text ( 255 ),
theZip Text ( 255 ),
theCountry Text ( 255 ),
theComments Text ( 255 ),
theUserID Text ( 255 ),
theTimeStamp DateTime,
theRecordID Long;

INSERT INTO tlkpCollateralManager
(
CollateralManagerID,
CollateralManagerName,
StreetAddress, City,
State,
Zip,
Country,
Comments,
CreatedBy,
CreatedAt
)

SELECT
[theRecordID] AS Expr10,
[theName] AS Expr9,
[theStreetAddress] AS Expr1,
[theCity] AS Expr2,
[theState] AS Expr3,
[theZip] AS Expr4,
[theCountry] AS Expr5,
[theComments] AS Expr6,
[theUserID] AS Expr7,
[theTimestamp] AS Expr8;
------------------------------------------------------------------
--
PeteCresswell
Sep 3 '07 #2
read your SQL statement. it names the fields for values to be inserted
into....but where are the values? you need to either write in hard-coded
values, or references that will return values, as

CurrentProject.Execute "INSERT INTO TransactionHistory " _
& "( FirstName, LastName, LastPaymentDate, " _
& "LastPaymentAmount ) SELECT '" & Me!ControlName _
& "', '" & Me!NextControlName & "', #" _
& Me!NextControlName & "#, " & Me!LastControlName, _
dbFailOnError

one way to get the correct syntax for SQL statements (for those of us who
aren't SQL whizzes), is to create the query in query Design view first, then
open the SQL View pane and copy/paste the statement into VBA - then break
out the statement into concatenated strings.

hth
"gmazza" <u37142@uwewrote in message news:77af4ff7945cb@uwe...
Hi there,
I am trying to insert 4 fields into a table grabbing the 4 fields from a
form,
here is my code:
Private Sub LastPaymentAmount_AfterUpdate()

Dim CurrentProject As DAO.Database
Set CurrentProject = CurrentDB()

'CurrentProject.Execute "Insert into TransactionHistory values(FirstName,
LastName, LastPaymentDate, LastPaymentAmount)", dbFailOnError

End Sub

and I keep getting a too few parameters error on the Execute statement.
Also, I just pasted my code in, the Execute statement is actually all on
one
line,
Thanks in advance for your help!
GM

Sep 3 '07 #3
Thanks a ton Tina, worked perfect!!

tina wrote:
>read your SQL statement. it names the fields for values to be inserted
into....but where are the values? you need to either write in hard-coded
values, or references that will return values, as

CurrentProject.Execute "INSERT INTO TransactionHistory " _
& "( FirstName, LastName, LastPaymentDate, " _
& "LastPaymentAmount ) SELECT '" & Me!ControlName _
& "', '" & Me!NextControlName & "', #" _
& Me!NextControlName & "#, " & Me!LastControlName, _
dbFailOnError

one way to get the correct syntax for SQL statements (for those of us who
aren't SQL whizzes), is to create the query in query Design view first, then
open the SQL View pane and copy/paste the statement into VBA - then break
out the statement into concatenated strings.

hth
>Hi there,
I am trying to insert 4 fields into a table grabbing the 4 fields from a form,
[quoted text clipped - 14 lines]
>Thanks in advance for your help!
GM
Sep 3 '07 #4
you're welcome :)
"gmazza" <u37142@uwewrote in message news:77aff661a098e@uwe...
Thanks a ton Tina, worked perfect!!

tina wrote:
read your SQL statement. it names the fields for values to be inserted
into....but where are the values? you need to either write in hard-coded
values, or references that will return values, as

CurrentProject.Execute "INSERT INTO TransactionHistory " _
& "( FirstName, LastName, LastPaymentDate, " _
& "LastPaymentAmount ) SELECT '" & Me!ControlName _
& "', '" & Me!NextControlName & "', #" _
& Me!NextControlName & "#, " & Me!LastControlName, _
dbFailOnError

one way to get the correct syntax for SQL statements (for those of us who
aren't SQL whizzes), is to create the query in query Design view first,
then
open the SQL View pane and copy/paste the statement into VBA - then break
out the statement into concatenated strings.

hth
Hi there,
I am trying to insert 4 fields into a table grabbing the 4 fields from
a form,
[quoted text clipped - 14 lines]
Thanks in advance for your help!
GM

Sep 4 '07 #5

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

Similar topics

3
by: jj | last post by:
I've got a form button that fires off 3 queries but if the first query returns an error, I don't want the other two queries to happen. Example: first query runs an insert from a linked table but...
1
by: Bob Darlington | last post by:
I'm trying to get the following simplified test query to work so that I can apply it to a more complex final query. I get a 'Too few parameters' error when I try to run the following append query:...
2
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks (...
12
by: ColinWard | last post by:
Hi. I am trying to run the following code when the user clicks a button, but I am getting a syntax error in the SQL. I have a feeling it has to do with brackets. Can anyone help? here is the...
8
by: RC | last post by:
In my Access 2002 form, I have a combo box and on the AfterUpdate event I use DoCmd.RunSQL ("UPDATE .... to update records in a table. When it starts to run I get a message "You are about to...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
4
by: sara | last post by:
Hi - All is fine if I open my form, do something, then close it. However, if I just open it, then press the Close button (or go into design view), I get "object variable or with Block variable...
4
by: HeislerKurt | last post by:
I'm getting the infamous error, "Too few parameters. Expected 2", when executing an update SQL statement in VBA. I assume it's a SQL syntax issue, but I can't find the problem, and I used a VBA...
5
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.