Thank you Mr. Vinson for your help.
I tried using the following code to update my hours based on a begin
date and an end date entered by the user.
I have a combo box to select the workhrs ategory (like clea_hrs or
store_hrs) then text boxes to enter begin date, end date and the hours
for the selected category on my form. I also have text boxes that
obtain the person id and project id from a different form
My requirement here is that if a user enters a begin date that is
greater than the maximum date in the database for this particular
criteria (projectid, personid..), then the code creates dates by
incrementing them by 7 days at a time and inputting the hours entered
for all the dates. If the begin date is less than the max date and the
end date is less than the max date too, only update hrs takes place. If
the end date is greater than max date an dthe begin date is less than
max date, update hours takes place until the max date and the dates and
hours are added from then on.
But my code gives me compile errors. I guess it has to do with the SQL
statements spanning multiple lines. I tried using the _ at the end of
each line but no use.
Can you please help me here?
Dim db As DAO.Database
Dim dbegindate As Date
Dim denddate As Date
Dim dmaxdate As Date
Set db = CurrentDb()
myField = cbadminhrs.Value
dbegindate = Txtbegindate.Value
denddate = Txtenddate.Value
dmaxdate = DMax(Wdate, qryAdmindata)
stadminhrs = Forms![frmbulkhrs]![cbadminhrs]
If DMax(Wdate, qryAdmindata) <= dbegindate Then
strqryinsert = "INSERT INTO tblworkhrs(stadminhrs, [WDate])" & _
"SELECT Forms![frmbulkhrs]![Txthrs]" & _
"DateAdd("d", 7*[N], dbegindate" & _
"FROM Num" & _
"WHERE personid=forms![frmbulkhrs]!personid AND
projectid=forms![frmbulkhrs]!projectid" & _
"AND DateAdd("d", 7*[N], dbegindate) <=" & _
"denddate;"
db.Execute strqryinsert, dbFailOnError
Else
If DMax(Wdate, qryAdmindata) >= denddate Then
RunSQL ("Update [tblworkhrs] SET [" & myField &
"]=Forms![frmbulkhrs]![Txthrs]"& _
"WHERE personid=forms![frmbulkhrs]!personid AND
projectid=forms![frmbulkhrs]!projectid" & _
"AND WDate>=dbegindate AND Wdate<=denddate");
Else
If DMax(Wdate, qryAdmindata) < denddate Then
RunSQL ("Update tblworkhrs SET ["& myField
&"]=Forms![frmbulkhrs]![Txthrs]" & _
"WHERE personid=forms![frmbulkhrs]!personid AND
projectid=forms![frmbulkhrs]!projectid" & _
"AND WDate>=dbegindate AND denddate<=Wdate");
RumSQL ("INSERT INTO tblworkhrs(stadminhrs, [WDate])" & _
"SELECT Forms![frmbulkhrs]![Txthrs]" & _
"DateAdd("d", 7*[N], dmaxdate" & _
"FROM Num" & _
"WHERE personid=forms![frmbulkhrs]!personid AND
projectid=forms![frmbulkhrs]!projectid" & _
" AND DateAdd("d", 7*[N], dmaxdate) <=" & _
"denddate;"
End Sub
Thank you very much....
|