Autofill subform when move to new record on Main form

S

Steve Sanford

Barb,
Still trying to understand the Insert Into statement to help make it work -
Do the Names of the text boxes in the Subform(tied to TimecardMDJeff) have to
Match the names that is after the Values part of the Insert statement -
when and why use -r.Fields(7) and the others ones like this.

No. The SQL "INSERT" inserts the record into the table. In your case, the
table is "TimeCardMDJEFF".
You would need to requery the subform to see the changes/added records.
 
B

babs

Steve,
I added the comma after name on both sql - but now getting a different error -
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Steve Sanford said:
Barb,

When you changed the field names in the insert statement, a comma was also
removed. A comma must be at the end of this line (after name, but inside the
quote):

sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"

Add the last comma, and it should run correctly.


don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP

"r" is the record set name and "r.Fields(6)" is the 7th field in the
recordset.

The record set field numbers are zero based, so the first field is zero, the
2nd field is 1, the third field is 2,........

Using "r.Fields(6)" is a way of getting the data from a field in a record
set without knowing the name if the field. Instead of "r.Fields(6)" ,
I could have used r.Fields("[Hours(ST)]").

In the recordset "r":
Field # Your Name
-------------------------------------
0 [Man Name]
1 [Job #]
2 [name]
3 [Date]
4 Workdate
5 [Day]
6 [Hours(ST)]
7 ActualRate



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
Yeah - I know they should use the SS# as PK - but they have been doingthis
for years and seems to be okay.

I added a new record on main for new weekend date- have people on fri. of
prev. week - added All of your wonderful suggest code to the button on click
event

I am getting Error on Insert Into - then Done- but no records show up.
a few of the field names- I changed to reflex there name - job is Job
#,job name is Name, ST is HOurs(ST) Not sure but just always add the [ ]
just in case.

below is the code I have in it- just grab the 2 sections out. I really
don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP



'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"


'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name]"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"



AGAIN - thanks a ton for helping!!
Barb
Steve Sanford said:
Barb,

If you want to use a list box instead of or in addition to the combo box,
you could have a multiselect list box that would list the workers. You select
one or more people, then click on a button. It could look to see if there was
a record for the previous Fri and add records for the week. If there wasn't a
record record, it could add a weeks worth of blank records for him.


Another question....(I know - but it is important).

What do you do if you have two John Smiths or Jim Jones?? Since you use a
person's name, how do you tell them apart??



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
this was what you stated before and this is what I would love - Also I think
the Insert 6 record button (code in previous posts)I have on the main form
with the man name combo box would take care of inserting the records - for a
New man not sched. last week.

Your prev. post
If I understand correctly, if there were two workers (Perl and Earl), you
would want to:

1) look at the previous friday's schedule
2) insert 6 records (Mon - Sat) records for this week's jobs for Perl and
3) insert 6 records (Mon - Sat) records for this week's jobs for Earl


If there were 10 workers on the previous friday, you would want 60 records
entered??

Thanks sooo much for still helping would love to get it done Before Thurs.
if possible.

Barb


:

Barb,

Is the main form recordsource a query? No it is just a table for the Week

I would recommend using a query for the main form record source. A table is
just a bucket the you put data into; it is not guaranteed to be in any order,
whereas a query is sortable.


I have 98% of the code done. I have a pretty good idea of what you want
done, but I don't know *how* you do it.

Let's say you have one worker "Bob".
Bob worked 9/14 - 9/18/2009.
NO records have been entered for the week 9/21 - 9/25/2009. (Week ending 9/26)
And let's say today is Sun. 9/20/2009.

So, my questions are:

- Is 9/27/2009 already entered in the main form? (do you pre-enter sundays
for the year?)


- Do you want to select 9/20/2009 in the main form and have the code enter
records for 9/21 - 9/25 (9/27 must already be entered in the main form)

- Do you want to select 9/20/2009 in the main form and have the code enter
the next sunday date (9/27), then have the code enter the records for the
week 9/21 - 9/25?

- Do you want to enter 9/27 in the main form, then select it and have the
code enter the new records for 9/21 - 9/25?


I'm looking for how you manually add records now.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

You have the TimecardMdJeff table correct!

What is the name of the main form table? WeekEndDate


Is the main form recordsource a query? No it is just a table for the Week
End Date - ie. just 52 records for one year. The combo box on the main for
is not bound and just set up for now to list Available people to schedule
when click on them - would like to be able to insert their 6 new records
based on the previous week.

For next post - we schedule Sunday night or very early Sunday morning.

thanks again for helping ! would love some code to help with your above
ideas - it is really what I would like to have happen.
Barb


:

OK, now I need to get my head around *when* you add the new week
records........

Here is a sample of a few records for the data - The mainform is just Week
End date so pretty self explanitory there - thinking would have the List box
instead of combo box of who to sched. on that mainform like have now

For subform
Man Name,Job#,Name(actually job name),Date(which is Week End Date),
Workdate,Day,ST(for hours in straight time),OT,DT,ActualRate - there are more
Smith, Rick ;80140020 ;The Legacy at Millennium Park; 9/6/09; 8/31/09;Mon;
8;other hours for overtime double time are blank, $28.20
Smith, Rick 90170054 Outdoor Pipe at 1060 Northpoint 9/6/09; 9/1/09 Tues 8
$28.20
Smith, Rick 80140020 The Legacy at Millennium Park 9/6/09; 9/2/09Wed 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/3/09Thur 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/4/09Fri 8
$28.20



Given the records above, I think the main form table already has 9/6/2009
entered.

So do you want to select 9/6/2009 in the main form, have a new record
entered in the main form with a date of "9/13/2009" , THEN find everyone that
worked on 9/4/2009 and enter records in the table "TimeCardMDJEFF" for the
dates 9/7/2009 thru 9/11/2009?



Which brings up another question: do you want {Mon thru Fri} or {Mon thru
Sat}??
 
B

babs

Steve, - reposting not sure if you see this or if it fell through the cracks-

sorry I just think I am close -thanks to you - not sure of why the error??

I added the comma after name on both sql - but now getting a different error
-
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last
Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

thanks soo much,
Barb
 
S

Steve Sanford

Yes, still here.

When you got the error, what line was highlighted?

Have you tried using " Debug.Print sSQL" statements after the sSQL lines
to see if the SQL statement are formed correctly?

When you look at the line in the debug window, the delimiters for field
types are:

Type Delimiters Example
------------------------------------------
strings " " or ' ' "Hi" or 'Hi'
dates # # #1/1/2009#
numbers no delimiters 28.50


Using data you provided, I put the sSQL lines in my code and ran it. The
debug window showed the value for "[Job #]" didn't have quotes around it.


Here is the modified insert SQL line:

'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, """ & r.Fields(1)
sSQL = sSQL & """, """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
I added the comma after name on both sql - but now getting a different error -
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Steve Sanford said:
Barb,

When you changed the field names in the insert statement, a comma was also
removed. A comma must be at the end of this line (after name, but inside the
quote):

sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"

Add the last comma, and it should run correctly.


don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP

"r" is the record set name and "r.Fields(6)" is the 7th field in the
recordset.

The record set field numbers are zero based, so the first field is zero, the
2nd field is 1, the third field is 2,........

Using "r.Fields(6)" is a way of getting the data from a field in a record
set without knowing the name if the field. Instead of "r.Fields(6)" ,
I could have used r.Fields("[Hours(ST)]").

In the recordset "r":
Field # Your Name
-------------------------------------
0 [Man Name]
1 [Job #]
2 [name]
3 [Date]
4 Workdate
5 [Day]
6 [Hours(ST)]
7 ActualRate



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
Yeah - I know they should use the SS# as PK - but they have been doingthis
for years and seems to be okay.

I added a new record on main for new weekend date- have people on fri. of
prev. week - added All of your wonderful suggest code to the button on click
event

I am getting Error on Insert Into - then Done- but no records show up.
a few of the field names- I changed to reflex there name - job is Job
#,job name is Name, ST is HOurs(ST) Not sure but just always add the [ ]
just in case.

below is the code I have in it- just grab the 2 sections out. I really
don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP



'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"


'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name]"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"



AGAIN - thanks a ton for helping!!
Barb
:

Barb,

If you want to use a list box instead of or in addition to the combo box,
you could have a multiselect list box that would list the workers. You select
one or more people, then click on a button. It could look to see if there was
a record for the previous Fri and add records for the week. If there wasn't a
record record, it could add a weeks worth of blank records for him.


Another question....(I know - but it is important).

What do you do if you have two John Smiths or Jim Jones?? Since you use a
person's name, how do you tell them apart??



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
this was what you stated before and this is what I would love - Also I think
the Insert 6 record button (code in previous posts)I have on the main form
with the man name combo box would take care of inserting the records - for a
New man not sched. last week.

Your prev. post
If I understand correctly, if there were two workers (Perl and Earl), you
would want to:

1) look at the previous friday's schedule
2) insert 6 records (Mon - Sat) records for this week's jobs for Perl and
3) insert 6 records (Mon - Sat) records for this week's jobs for Earl


If there were 10 workers on the previous friday, you would want 60 records
entered??

Thanks sooo much for still helping would love to get it done Before Thurs.
if possible.

Barb


:

Barb,

Is the main form recordsource a query? No it is just a table for the Week

I would recommend using a query for the main form record source. A table is
just a bucket the you put data into; it is not guaranteed to be in any order,
whereas a query is sortable.


I have 98% of the code done. I have a pretty good idea of what you want
done, but I don't know *how* you do it.

Let's say you have one worker "Bob".
Bob worked 9/14 - 9/18/2009.
NO records have been entered for the week 9/21 - 9/25/2009. (Week ending 9/26)
And let's say today is Sun. 9/20/2009.

So, my questions are:

- Is 9/27/2009 already entered in the main form? (do you pre-enter sundays
for the year?)


- Do you want to select 9/20/2009 in the main form and have the code enter
records for 9/21 - 9/25 (9/27 must already be entered in the main form)

- Do you want to select 9/20/2009 in the main form and have the code enter
the next sunday date (9/27), then have the code enter the records for the
week 9/21 - 9/25?

- Do you want to enter 9/27 in the main form, then select it and have the
code enter the new records for 9/21 - 9/25?


I'm looking for how you manually add records now.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

You have the TimecardMdJeff table correct!

What is the name of the main form table? WeekEndDate


Is the main form recordsource a query? No it is just a table for the Week
End Date - ie. just 52 records for one year. The combo box on the main for
is not bound and just set up for now to list Available people to schedule
when click on them - would like to be able to insert their 6 new records
based on the previous week.

For next post - we schedule Sunday night or very early Sunday morning.

thanks again for helping ! would love some code to help with your above
ideas - it is really what I would like to have happen.
Barb


:

OK, now I need to get my head around *when* you add the new week
records........

Here is a sample of a few records for the data - The mainform is just Week
End date so pretty self explanitory there - thinking would have the List box
instead of combo box of who to sched. on that mainform like have now

For subform
Man Name,Job#,Name(actually job name),Date(which is Week End Date),
Workdate,Day,ST(for hours in straight time),OT,DT,ActualRate - there are more
Smith, Rick ;80140020 ;The Legacy at Millennium Park; 9/6/09; 8/31/09;Mon;
8;other hours for overtime double time are blank, $28.20
Smith, Rick 90170054 Outdoor Pipe at 1060 Northpoint 9/6/09; 9/1/09 Tues 8
$28.20
Smith, Rick 80140020 The Legacy at Millennium Park 9/6/09; 9/2/09Wed 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/3/09Thur 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/4/09Fri 8
$28.20



Given the records above, I think the main form table already has 9/6/2009
entered.

So do you want to select 9/6/2009 in the main form, have a new record
entered in the main form with a date of "9/13/2009" , THEN find everyone that
worked on 9/4/2009 and enter records in the table "TimeCardMDJEFF" for the
dates 9/7/2009 thru 9/11/2009?



Which brings up another question: do you want {Mon thru Fri} or {Mon thru
Sat}??
 
B

babs

Steve,
I pasted the code you posted in and changed the table now to the query that
is now tied to the subform(recordsource)-
but I am getting the EXACT SAme error

Search error 3075
inside - syntax error in query expression '42.05'
not sure on where the debug print should show up???

I tried a toggle break and pointed to the code and basically seems okay???
not sure why the error and no records added ??

thanks for still helpingBarb


'create the insert string
sSQL = "INSERT INTO [JeffTime Card MD Query]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, """ & r.Fields(1)
sSQL = sSQL & """, """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL

Steve Sanford said:
Yes, still here.

When you got the error, what line was highlighted?

Have you tried using " Debug.Print sSQL" statements after the sSQL lines
to see if the SQL statement are formed correctly?

When you look at the line in the debug window, the delimiters for field
types are:

Type Delimiters Example
------------------------------------------
strings " " or ' ' "Hi" or 'Hi'
dates # # #1/1/2009#
numbers no delimiters 28.50


Using data you provided, I put the sSQL lines in my code and ran it. The
debug window showed the value for "[Job #]" didn't have quotes around it.


Here is the modified insert SQL line:

'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, """ & r.Fields(1)
sSQL = sSQL & """, """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
I added the comma after name on both sql - but now getting a different error -
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Steve Sanford said:
Barb,

When you changed the field names in the insert statement, a comma was also
removed. A comma must be at the end of this line (after name, but inside the
quote):

sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"

Add the last comma, and it should run correctly.



don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP

"r" is the record set name and "r.Fields(6)" is the 7th field in the
recordset.

The record set field numbers are zero based, so the first field is zero, the
2nd field is 1, the third field is 2,........

Using "r.Fields(6)" is a way of getting the data from a field in a record
set without knowing the name if the field. Instead of "r.Fields(6)" ,
I could have used r.Fields("[Hours(ST)]").

In the recordset "r":
Field # Your Name
-------------------------------------
0 [Man Name]
1 [Job #]
2 [name]
3 [Date]
4 Workdate
5 [Day]
6 [Hours(ST)]
7 ActualRate



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
Yeah - I know they should use the SS# as PK - but they have been doingthis
for years and seems to be okay.

I added a new record on main for new weekend date- have people on fri. of
prev. week - added All of your wonderful suggest code to the button on click
event

I am getting Error on Insert Into - then Done- but no records show up.
a few of the field names- I changed to reflex there name - job is Job
#,job name is Name, ST is HOurs(ST) Not sure but just always add the [ ]
just in case.

below is the code I have in it- just grab the 2 sections out. I really
don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP



'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"


'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name]"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"



AGAIN - thanks a ton for helping!!
Barb
:

Barb,

If you want to use a list box instead of or in addition to the combo box,
you could have a multiselect list box that would list the workers. You select
one or more people, then click on a button. It could look to see if there was
a record for the previous Fri and add records for the week. If there wasn't a
record record, it could add a weeks worth of blank records for him.


Another question....(I know - but it is important).

What do you do if you have two John Smiths or Jim Jones?? Since you use a
person's name, how do you tell them apart??



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
this was what you stated before and this is what I would love - Also I think
the Insert 6 record button (code in previous posts)I have on the main form
with the man name combo box would take care of inserting the records - for a
New man not sched. last week.

Your prev. post
If I understand correctly, if there were two workers (Perl and Earl), you
would want to:

1) look at the previous friday's schedule
2) insert 6 records (Mon - Sat) records for this week's jobs for Perl and
3) insert 6 records (Mon - Sat) records for this week's jobs for Earl


If there were 10 workers on the previous friday, you would want 60 records
entered??

Thanks sooo much for still helping would love to get it done Before Thurs.
if possible.

Barb


:

Barb,

Is the main form recordsource a query? No it is just a table for the Week

I would recommend using a query for the main form record source. A table is
just a bucket the you put data into; it is not guaranteed to be in any order,
whereas a query is sortable.


I have 98% of the code done. I have a pretty good idea of what you want
done, but I don't know *how* you do it.

Let's say you have one worker "Bob".
Bob worked 9/14 - 9/18/2009.
NO records have been entered for the week 9/21 - 9/25/2009. (Week ending 9/26)
And let's say today is Sun. 9/20/2009.

So, my questions are:

- Is 9/27/2009 already entered in the main form? (do you pre-enter sundays
for the year?)


- Do you want to select 9/20/2009 in the main form and have the code enter
records for 9/21 - 9/25 (9/27 must already be entered in the main form)

- Do you want to select 9/20/2009 in the main form and have the code enter
the next sunday date (9/27), then have the code enter the records for the
week 9/21 - 9/25?

- Do you want to enter 9/27 in the main form, then select it and have the
code enter the new records for 9/21 - 9/25?


I'm looking for how you manually add records now.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

You have the TimecardMdJeff table correct!

What is the name of the main form table? WeekEndDate


Is the main form recordsource a query? No it is just a table for the Week
End Date - ie. just 52 records for one year. The combo box on the main for
is not bound and just set up for now to list Available people to schedule
when click on them - would like to be able to insert their 6 new records
based on the previous week.

For next post - we schedule Sunday night or very early Sunday morning.

thanks again for helping ! would love some code to help with your above
ideas - it is really what I would like to have happen.
Barb


:

OK, now I need to get my head around *when* you add the new week
records........

Here is a sample of a few records for the data - The mainform is just Week
End date so pretty self explanitory there - thinking would have the List box
instead of combo box of who to sched. on that mainform like have now

For subform
Man Name,Job#,Name(actually job name),Date(which is Week End Date),
Workdate,Day,ST(for hours in straight time),OT,DT,ActualRate - there are more
Smith, Rick ;80140020 ;The Legacy at Millennium Park; 9/6/09; 8/31/09;Mon;
8;other hours for overtime double time are blank, $28.20
Smith, Rick 90170054 Outdoor Pipe at 1060 Northpoint 9/6/09; 9/1/09 Tues 8
$28.20
Smith, Rick 80140020 The Legacy at Millennium Park 9/6/09; 9/2/09Wed 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/3/09Thur 8
 
B

babs

Looked at the Immediate Window in Visual code view and see this below- don't
know if the order
In the tables behind the scenes for some strange reason Job # is a number
field - not sure if that would explain the error and where would I change the
code.

Immediate window - not sure also why grabbing Mon and not Fri???
INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
"1800270", "U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0,
42.05;
INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
"1800270", "U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0,
42.05;
INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
"1800270", "U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0,
42.05;
INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
"1800270", "U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0,
42.05;
INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
"1800270", "U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0,
42.05;


Steve Sanford said:
Yes, still here.

When you got the error, what line was highlighted?

Have you tried using " Debug.Print sSQL" statements after the sSQL lines
to see if the SQL statement are formed correctly?

When you look at the line in the debug window, the delimiters for field
types are:

Type Delimiters Example
------------------------------------------
strings " " or ' ' "Hi" or 'Hi'
dates # # #1/1/2009#
numbers no delimiters 28.50


Using data you provided, I put the sSQL lines in my code and ran it. The
debug window showed the value for "[Job #]" didn't have quotes around it.


Here is the modified insert SQL line:

'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, """ & r.Fields(1)
sSQL = sSQL & """, """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
I added the comma after name on both sql - but now getting a different error -
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Steve Sanford said:
Barb,

When you changed the field names in the insert statement, a comma was also
removed. A comma must be at the end of this line (after name, but inside the
quote):

sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"

Add the last comma, and it should run correctly.



don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP

"r" is the record set name and "r.Fields(6)" is the 7th field in the
recordset.

The record set field numbers are zero based, so the first field is zero, the
2nd field is 1, the third field is 2,........

Using "r.Fields(6)" is a way of getting the data from a field in a record
set without knowing the name if the field. Instead of "r.Fields(6)" ,
I could have used r.Fields("[Hours(ST)]").

In the recordset "r":
Field # Your Name
-------------------------------------
0 [Man Name]
1 [Job #]
2 [name]
3 [Date]
4 Workdate
5 [Day]
6 [Hours(ST)]
7 ActualRate



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
Yeah - I know they should use the SS# as PK - but they have been doingthis
for years and seems to be okay.

I added a new record on main for new weekend date- have people on fri. of
prev. week - added All of your wonderful suggest code to the button on click
event

I am getting Error on Insert Into - then Done- but no records show up.
a few of the field names- I changed to reflex there name - job is Job
#,job name is Name, ST is HOurs(ST) Not sure but just always add the [ ]
just in case.

below is the code I have in it- just grab the 2 sections out. I really
don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP



'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"


'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name]"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"



AGAIN - thanks a ton for helping!!
Barb
:

Barb,

If you want to use a list box instead of or in addition to the combo box,
you could have a multiselect list box that would list the workers. You select
one or more people, then click on a button. It could look to see if there was
a record for the previous Fri and add records for the week. If there wasn't a
record record, it could add a weeks worth of blank records for him.


Another question....(I know - but it is important).

What do you do if you have two John Smiths or Jim Jones?? Since you use a
person's name, how do you tell them apart??



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
this was what you stated before and this is what I would love - Also I think
the Insert 6 record button (code in previous posts)I have on the main form
with the man name combo box would take care of inserting the records - for a
New man not sched. last week.

Your prev. post
If I understand correctly, if there were two workers (Perl and Earl), you
would want to:

1) look at the previous friday's schedule
2) insert 6 records (Mon - Sat) records for this week's jobs for Perl and
3) insert 6 records (Mon - Sat) records for this week's jobs for Earl


If there were 10 workers on the previous friday, you would want 60 records
entered??

Thanks sooo much for still helping would love to get it done Before Thurs.
if possible.

Barb


:

Barb,

Is the main form recordsource a query? No it is just a table for the Week

I would recommend using a query for the main form record source. A table is
just a bucket the you put data into; it is not guaranteed to be in any order,
whereas a query is sortable.


I have 98% of the code done. I have a pretty good idea of what you want
done, but I don't know *how* you do it.

Let's say you have one worker "Bob".
Bob worked 9/14 - 9/18/2009.
NO records have been entered for the week 9/21 - 9/25/2009. (Week ending 9/26)
And let's say today is Sun. 9/20/2009.

So, my questions are:

- Is 9/27/2009 already entered in the main form? (do you pre-enter sundays
for the year?)


- Do you want to select 9/20/2009 in the main form and have the code enter
records for 9/21 - 9/25 (9/27 must already be entered in the main form)

- Do you want to select 9/20/2009 in the main form and have the code enter
the next sunday date (9/27), then have the code enter the records for the
week 9/21 - 9/25?

- Do you want to enter 9/27 in the main form, then select it and have the
code enter the new records for 9/21 - 9/25?


I'm looking for how you manually add records now.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

You have the TimecardMdJeff table correct!

What is the name of the main form table? WeekEndDate


Is the main form recordsource a query? No it is just a table for the Week
End Date - ie. just 52 records for one year. The combo box on the main for
is not bound and just set up for now to list Available people to schedule
when click on them - would like to be able to insert their 6 new records
based on the previous week.

For next post - we schedule Sunday night or very early Sunday morning.

thanks again for helping ! would love some code to help with your above
ideas - it is really what I would like to have happen.
Barb


:

OK, now I need to get my head around *when* you add the new week
records........

Here is a sample of a few records for the data - The mainform is just Week
End date so pretty self explanitory there - thinking would have the List box
instead of combo box of who to sched. on that mainform like have now

For subform
Man Name,Job#,Name(actually job name),Date(which is Week End Date),
Workdate,Day,ST(for hours in straight time),OT,DT,ActualRate - there are more
Smith, Rick ;80140020 ;The Legacy at Millennium Park; 9/6/09; 8/31/09;Mon;
8;other hours for overtime double time are blank, $28.20
Smith, Rick 90170054 Outdoor Pipe at 1060 Northpoint 9/6/09; 9/1/09 Tues 8
$28.20
Smith, Rick 80140020 The Legacy at Millennium Park 9/6/09; 9/2/09Wed 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/3/09Thur 8
 
B

babs

Steve,
Was able to modify code to get rid of "" for job # and immediate window
shows the 1 Record and no quotes around Job # - should be good since it is a
number field. - see below - STILL GETTING SAME SYNTAX ERROR
not sure why grabbing the Mon - and shouldn't it show 6 records added in
immediate window?? Help??

'create the insert string
sSQL = "INSERT INTO [JeffTime Card MD Query]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL

INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE", 1800270,
"U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0, 42.05;

Steve Sanford said:
Yes, still here.

When you got the error, what line was highlighted?

Have you tried using " Debug.Print sSQL" statements after the sSQL lines
to see if the SQL statement are formed correctly?

When you look at the line in the debug window, the delimiters for field
types are:

Type Delimiters Example
------------------------------------------
strings " " or ' ' "Hi" or 'Hi'
dates # # #1/1/2009#
numbers no delimiters 28.50


Using data you provided, I put the sSQL lines in my code and ran it. The
debug window showed the value for "[Job #]" didn't have quotes around it.


Here is the modified insert SQL line:

'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, """ & r.Fields(1)
sSQL = sSQL & """, """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
I added the comma after name on both sql - but now getting a different error -
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Steve Sanford said:
Barb,

When you changed the field names in the insert statement, a comma was also
removed. A comma must be at the end of this line (after name, but inside the
quote):

sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"

Add the last comma, and it should run correctly.



don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP

"r" is the record set name and "r.Fields(6)" is the 7th field in the
recordset.

The record set field numbers are zero based, so the first field is zero, the
2nd field is 1, the third field is 2,........

Using "r.Fields(6)" is a way of getting the data from a field in a record
set without knowing the name if the field. Instead of "r.Fields(6)" ,
I could have used r.Fields("[Hours(ST)]").

In the recordset "r":
Field # Your Name
-------------------------------------
0 [Man Name]
1 [Job #]
2 [name]
3 [Date]
4 Workdate
5 [Day]
6 [Hours(ST)]
7 ActualRate



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
Yeah - I know they should use the SS# as PK - but they have been doingthis
for years and seems to be okay.

I added a new record on main for new weekend date- have people on fri. of
prev. week - added All of your wonderful suggest code to the button on click
event

I am getting Error on Insert Into - then Done- but no records show up.
a few of the field names- I changed to reflex there name - job is Job
#,job name is Name, ST is HOurs(ST) Not sure but just always add the [ ]
just in case.

below is the code I have in it- just grab the 2 sections out. I really
don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP



'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"


'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name]"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"



AGAIN - thanks a ton for helping!!
Barb
:

Barb,

If you want to use a list box instead of or in addition to the combo box,
you could have a multiselect list box that would list the workers. You select
one or more people, then click on a button. It could look to see if there was
a record for the previous Fri and add records for the week. If there wasn't a
record record, it could add a weeks worth of blank records for him.


Another question....(I know - but it is important).

What do you do if you have two John Smiths or Jim Jones?? Since you use a
person's name, how do you tell them apart??



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
this was what you stated before and this is what I would love - Also I think
the Insert 6 record button (code in previous posts)I have on the main form
with the man name combo box would take care of inserting the records - for a
New man not sched. last week.

Your prev. post
If I understand correctly, if there were two workers (Perl and Earl), you
would want to:

1) look at the previous friday's schedule
2) insert 6 records (Mon - Sat) records for this week's jobs for Perl and
3) insert 6 records (Mon - Sat) records for this week's jobs for Earl


If there were 10 workers on the previous friday, you would want 60 records
entered??

Thanks sooo much for still helping would love to get it done Before Thurs.
if possible.

Barb


:

Barb,

Is the main form recordsource a query? No it is just a table for the Week

I would recommend using a query for the main form record source. A table is
just a bucket the you put data into; it is not guaranteed to be in any order,
whereas a query is sortable.


I have 98% of the code done. I have a pretty good idea of what you want
done, but I don't know *how* you do it.

Let's say you have one worker "Bob".
Bob worked 9/14 - 9/18/2009.
NO records have been entered for the week 9/21 - 9/25/2009. (Week ending 9/26)
And let's say today is Sun. 9/20/2009.

So, my questions are:

- Is 9/27/2009 already entered in the main form? (do you pre-enter sundays
for the year?)


- Do you want to select 9/20/2009 in the main form and have the code enter
records for 9/21 - 9/25 (9/27 must already be entered in the main form)

- Do you want to select 9/20/2009 in the main form and have the code enter
the next sunday date (9/27), then have the code enter the records for the
week 9/21 - 9/25?

- Do you want to enter 9/27 in the main form, then select it and have the
code enter the new records for 9/21 - 9/25?


I'm looking for how you manually add records now.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

You have the TimecardMdJeff table correct!

What is the name of the main form table? WeekEndDate


Is the main form recordsource a query? No it is just a table for the Week
End Date - ie. just 52 records for one year. The combo box on the main for
is not bound and just set up for now to list Available people to schedule
when click on them - would like to be able to insert their 6 new records
based on the previous week.

For next post - we schedule Sunday night or very early Sunday morning.

thanks again for helping ! would love some code to help with your above
ideas - it is really what I would like to have happen.
Barb


:

OK, now I need to get my head around *when* you add the new week
records........

Here is a sample of a few records for the data - The mainform is just Week
End date so pretty self explanitory there - thinking would have the List box
instead of combo box of who to sched. on that mainform like have now

For subform
Man Name,Job#,Name(actually job name),Date(which is Week End Date),
Workdate,Day,ST(for hours in straight time),OT,DT,ActualRate - there are more
Smith, Rick ;80140020 ;The Legacy at Millennium Park; 9/6/09; 8/31/09;Mon;
8;other hours for overtime double time are blank, $28.20
Smith, Rick 90170054 Outdoor Pipe at 1060 Northpoint 9/6/09; 9/1/09 Tues 8
$28.20
Smith, Rick 80140020 The Legacy at Millennium Park 9/6/09; 9/2/09Wed 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/3/09Thur 8
 
B

babs

SORRY - It is grabbing the correct Job# and job name(from prev. Fri) and
putting the Mon all correct in the immedate window in VB view - just not sure
why the ERROR and shouldn't I be seeing the 6 records in the immediate
window>??? sorry for all the posts - just trying to get this done.

thanks,
barb

Steve Sanford said:
Yes, still here.

When you got the error, what line was highlighted?

Have you tried using " Debug.Print sSQL" statements after the sSQL lines
to see if the SQL statement are formed correctly?

When you look at the line in the debug window, the delimiters for field
types are:

Type Delimiters Example
------------------------------------------
strings " " or ' ' "Hi" or 'Hi'
dates # # #1/1/2009#
numbers no delimiters 28.50


Using data you provided, I put the sSQL lines in my code and ran it. The
debug window showed the value for "[Job #]" didn't have quotes around it.


Here is the modified insert SQL line:

'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF]"
sSQL = sSQL & " ([Man Name], [Job #],"
sSQL = sSQL & " [name], [Date],"
sSQL = sSQL & " Workdate, [Day],"
sSQL = sSQL & " [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, """ & r.Fields(1)
sSQL = sSQL & """, """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


babs said:
Steve,
I added the comma after name on both sql - but now getting a different error -
In title bar of box it says Search error 3075
inside - syntax error in query expression '42.05'

I looked it up but can figure out what is wrong???
inserted code below for both sSQL
I had to go out of town and just got back - really want to get this figured
out today if possible - thanks soo much for helping,
Barb

'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"



'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Steve Sanford said:
Barb,

When you changed the field names in the insert statement, a comma was also
removed. A comma must be at the end of this line (after name, but inside the
quote):

sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name],"

Add the last comma, and it should run correctly.



don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP

"r" is the record set name and "r.Fields(6)" is the 7th field in the
recordset.

The record set field numbers are zero based, so the first field is zero, the
2nd field is 1, the third field is 2,........

Using "r.Fields(6)" is a way of getting the data from a field in a record
set without knowing the name if the field. Instead of "r.Fields(6)" ,
I could have used r.Fields("[Hours(ST)]").

In the recordset "r":
Field # Your Name
-------------------------------------
0 [Man Name]
1 [Job #]
2 [name]
3 [Date]
4 Workdate
5 [Day]
6 [Hours(ST)]
7 ActualRate



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
Yeah - I know they should use the SS# as PK - but they have been doingthis
for years and seems to be okay.

I added a new record on main for new weekend date- have people on fri. of
prev. week - added All of your wonderful suggest code to the button on click
event

I am getting Error on Insert Into - then Done- but no records show up.
a few of the field names- I changed to reflex there name - job is Job
#,job name is Name, ST is HOurs(ST) Not sure but just always add the [ ]
just in case.

below is the code I have in it- just grab the 2 sections out. I really
don't get the Insert into code and what the last line(sSQL = sSQL & """, " &
r.Fields(6) & ", " & r.Fields(7) & ";") means???HELP



'- open a recordset based on the table "TimeCardMDJEFF" WHERE [date] =Last Fri
sSQL = "SELECT [Man Name], [Job #], [name],"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate"
sSQL = sSQL & " FROM TimeCardMDJEFF"
sSQL = sSQL & " WHERE [Workdate] = #" & dteFri & "#;"


'create the insert string
sSQL = "INSERT INTO [TimeCardMDJEFF] ([Man Name], [Job #], [name]"
sSQL = sSQL & " [Date], Workdate, [Day], [Hours(ST)], ActualRate)"
sSQL = sSQL & " VALUES (""" & r.Fields(0) & """, " & r.Fields(1)
sSQL = sSQL & ", """ & r.Fields(2) & """, #" & dteWeekEndDay
sSQL = sSQL & "#, #" & tmpDate & "#, """ & WkDay
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"



AGAIN - thanks a ton for helping!!
Barb
:

Barb,

If you want to use a list box instead of or in addition to the combo box,
you could have a multiselect list box that would list the workers. You select
one or more people, then click on a button. It could look to see if there was
a record for the previous Fri and add records for the week. If there wasn't a
record record, it could add a weeks worth of blank records for him.


Another question....(I know - but it is important).

What do you do if you have two John Smiths or Jim Jones?? Since you use a
person's name, how do you tell them apart??



HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

Steve,
this was what you stated before and this is what I would love - Also I think
the Insert 6 record button (code in previous posts)I have on the main form
with the man name combo box would take care of inserting the records - for a
New man not sched. last week.

Your prev. post
If I understand correctly, if there were two workers (Perl and Earl), you
would want to:

1) look at the previous friday's schedule
2) insert 6 records (Mon - Sat) records for this week's jobs for Perl and
3) insert 6 records (Mon - Sat) records for this week's jobs for Earl


If there were 10 workers on the previous friday, you would want 60 records
entered??

Thanks sooo much for still helping would love to get it done Before Thurs.
if possible.

Barb


:

Barb,

Is the main form recordsource a query? No it is just a table for the Week

I would recommend using a query for the main form record source. A table is
just a bucket the you put data into; it is not guaranteed to be in any order,
whereas a query is sortable.


I have 98% of the code done. I have a pretty good idea of what you want
done, but I don't know *how* you do it.

Let's say you have one worker "Bob".
Bob worked 9/14 - 9/18/2009.
NO records have been entered for the week 9/21 - 9/25/2009. (Week ending 9/26)
And let's say today is Sun. 9/20/2009.

So, my questions are:

- Is 9/27/2009 already entered in the main form? (do you pre-enter sundays
for the year?)


- Do you want to select 9/20/2009 in the main form and have the code enter
records for 9/21 - 9/25 (9/27 must already be entered in the main form)

- Do you want to select 9/20/2009 in the main form and have the code enter
the next sunday date (9/27), then have the code enter the records for the
week 9/21 - 9/25?

- Do you want to enter 9/27 in the main form, then select it and have the
code enter the new records for 9/21 - 9/25?


I'm looking for how you manually add records now.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


:

You have the TimecardMdJeff table correct!

What is the name of the main form table? WeekEndDate


Is the main form recordsource a query? No it is just a table for the Week
End Date - ie. just 52 records for one year. The combo box on the main for
is not bound and just set up for now to list Available people to schedule
when click on them - would like to be able to insert their 6 new records
based on the previous week.

For next post - we schedule Sunday night or very early Sunday morning.

thanks again for helping ! would love some code to help with your above
ideas - it is really what I would like to have happen.
Barb


:

OK, now I need to get my head around *when* you add the new week
records........

Here is a sample of a few records for the data - The mainform is just Week
End date so pretty self explanitory there - thinking would have the List box
instead of combo box of who to sched. on that mainform like have now

For subform
Man Name,Job#,Name(actually job name),Date(which is Week End Date),
Workdate,Day,ST(for hours in straight time),OT,DT,ActualRate - there are more
Smith, Rick ;80140020 ;The Legacy at Millennium Park; 9/6/09; 8/31/09;Mon;
8;other hours for overtime double time are blank, $28.20
Smith, Rick 90170054 Outdoor Pipe at 1060 Northpoint 9/6/09; 9/1/09 Tues 8
$28.20
Smith, Rick 80140020 The Legacy at Millennium Park 9/6/09; 9/2/09Wed 8
$28.20
Smith, Rick 80140014 Wheaton College Warrior Dome 9/6/09; 9/3/09Thur 8
 
S

Steve Sanford

window>??? sorry for all the posts - just trying to get this done.

No problems.

Did you remove the break point? (he said, clutching at straws). Did you
compare the current code you have to the code I originally posted; forgetting
the sSQL lines - are all the other lines there?


Normally I don't do this, but I need to see your MDB. If you would change/
delete any sensetive data (SSN, Addresses, Phone numbers), do a compact and
repair (maybe zip it) and send it to me??? There only needs to be a few
records - just enough to test. (I have A2K & A2K3.)
 
H

Hans Up

babs said:
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL

INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE", 1800270,
"U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0, 42.05;

You need a closing parenthesis for the list of VALUES. Change the last
line of your code which creates the insert string to:

sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ");"

I think the INSERT statement should look like this:

INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
1800270,
"U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0, 42.05);

Try pasting it into the SQL View of a new query and let us know whether
or not the INSERT is successful.
 
S

Steve Sanford

Good catch! I've looked at that line so much that I know I saw that closing
parenthesis... I swear I did!

:D

--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


Hans Up said:
babs said:
sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ";"

Debug.Print sSQL

INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE", 1800270,
"U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0, 42.05;

You need a closing parenthesis for the list of VALUES. Change the last
line of your code which creates the insert string to:

sSQL = sSQL & """, " & r.Fields(6) & ", " & r.Fields(7) & ");"

I think the INSERT statement should look like this:

INSERT INTO [JeffTime Card MD Query] ([Man Name], [Job #], [name], [Date],
Workdate, [Day], [Hours(ST)], ActualRate) VALUES ("BROOKS, CLAIRE",
1800270,
"U.S. Post Office, Rockford", #10/4/2009#, #9/28/2009#, "Mon", 0, 42.05);

Try pasting it into the SQL View of a new query and let us know whether
or not the INSERT is successful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top