P
Pragv
Thank you Mr. Douglas,
I now included the # delimiters.
Here's my original query in VBA code behind my form
strqryinsert = "INSERT INTO tblworkhours([" & stadminhrs & "], [WDate])
" & _
" SELECT " & Forms![frmbulkhrs]![txthours] & _
" , DateAdd('d', 7*[N], #" & dbegindate & "#) " & _
" FROM NUM " & _
" WHERE personid=" & Forms![frmbulkhrs]!PersonID & _
" AND projectid=" & Forms![frmbulkhrs]!ProjectId & _
" AND DateAdd('d', 7*[N], #" & dbegindate & "#) <= #" &
denddate & _
"#;"
Debug.Print strqryinsert
db.Execute strqryinsert, dbFailOnError
Here is what the debug.print gives when I'm debugging for some input
values
INSERT INTO tblworkhours(Admin_DocPrep_Hrs, [WDate]) SELECT 1 ,
DateAdd('d', 7*[N], #1/1/2007#) FROM NUM WHERE personid=1 AND
projectid=90 AND DateAdd('d', 7*[N], #1/1/2007#) <= #1/15/2007# ;
I still get the error about too few parameters expected 2.
The table that I'm inserting data into (tblworkhrs) has additional
fields in it with an auto number as primary id. But I'm inserting data
into only two fields. The default value for the rest of them is 0. Do
you think that's causing a problem?
Do I need to specifically input zeros into the rest of my fields (about
13-14 of them) through my query to get this to work?
Any help is greatly appreciated.
Thanks
I now included the # delimiters.
Here's my original query in VBA code behind my form
strqryinsert = "INSERT INTO tblworkhours([" & stadminhrs & "], [WDate])
" & _
" SELECT " & Forms![frmbulkhrs]![txthours] & _
" , DateAdd('d', 7*[N], #" & dbegindate & "#) " & _
" FROM NUM " & _
" WHERE personid=" & Forms![frmbulkhrs]!PersonID & _
" AND projectid=" & Forms![frmbulkhrs]!ProjectId & _
" AND DateAdd('d', 7*[N], #" & dbegindate & "#) <= #" &
denddate & _
"#;"
Debug.Print strqryinsert
db.Execute strqryinsert, dbFailOnError
Here is what the debug.print gives when I'm debugging for some input
values
INSERT INTO tblworkhours(Admin_DocPrep_Hrs, [WDate]) SELECT 1 ,
DateAdd('d', 7*[N], #1/1/2007#) FROM NUM WHERE personid=1 AND
projectid=90 AND DateAdd('d', 7*[N], #1/1/2007#) <= #1/15/2007# ;
I still get the error about too few parameters expected 2.
The table that I'm inserting data into (tblworkhrs) has additional
fields in it with an auto number as primary id. But I'm inserting data
into only two fields. The default value for the rest of them is 0. Do
you think that's causing a problem?
Do I need to specifically input zeros into the rest of my fields (about
13-14 of them) through my query to get this to work?
Any help is greatly appreciated.
Thanks
I doubt this is the error, but you're missing the # delimiters in your
DateAdd statements:
INSERT INTO tblworkhours(Admin_CR_Hrs, [WDate]) SELECT 1 ,
DateAdd('d', 7*[N],#1/1/2007#) FROM NUM WHERE personid=1 AND
projectid=1 AND DateAdd('d', 7*[N],#1/1/2007#) <= #1/15/2007# ;
The error message you're getting usually implies that you've misspelled the
names of fields that you're using in the SQL, but it's pretty hard to
misspell N! <g>
--
Doug Steele, Microsoft Access MVP
(no e-mails, please!)
Pragv said:I'm too tired at midnight to disentangle this. Could you please run
this with a breakpoint set, step through this statement, and post the
actual resulting value of strqryinsert that results? It may also help
to know the datatypes of all the relevant fields.
I used debug.print statement to get the value of the query for my
inputs
Here it is
INSERT INTO tblworkhours(Admin_CR_Hrs, [WDate]) SELECT 1 ,
DateAdd('d', 7*[N],1/1/2007) FROM NUM WHERE personid=1 AND
projectid=1 AND DateAdd('d', 7*[N],1/1/2007) <= #1/15/2007# ;
The query looks good to me . But when the next staement : db.Execute
strqryinsert, dbFailOnError is executed, I get the error 'Too few
parameters, expected 2.
I guess I never really did address the issue: WHY all this complexity?
Can you not work with bound forms?
I have bound forms for everything. But my users donot want to update
records one by one all the time. Some times they want to update their
hours for say a couple of months at a time.
They don't want to use the bond forms to update hours for each week.
They just want to be able to enter a date range and update a particular
category hours.
They still work with bound forms for updating records one by one.
Since I'm not sure what date ranges they would enter (whether an
existing date in the database or something for the future or just an
update), I had to do all this.
I hate the complexity too and as you can see, I'm struggling a little
too....
Thank you for all the help. I really appreciate your time for me.John W. Vinson[MVP]