472,955 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

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 2788
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.