dbTalk Databases Forums  

loop to take value from subform

comp.databases.ms-access comp.databases.ms-access


Discuss loop to take value from subform in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
flymo
 
Posts: n/a

Default loop to take value from subform - 08-12-2011 , 02:52 PM






Hello All
I am using Duane Hookums excellent recurring database file and I have
modified quite a bit.

I have come across a basic problem - the recurring code works great
when using a group of check boxes to generate a series of dates. The
code runs based on a value "group" in the main form:
If Me.grpRepeats = 2 Then
'runs code for recurring dates.

However when the choice is single dates these dates are entered
individually in a subform, the code updates a single date instead of
allowing me to add:
i add 12th, 13th & 14th dates (as below) 2011 - Morning , run the code
everything works ok, I change a parameter 12th.13th & 14th 2011 -
Afternoon and run again to create, the update over writes (as you
would expect.)

What I am need to do is add several single dates and loop through
12-9-2011 Morning etc
13-11-2011 Morning etc
14-12-2011 Morning etc
etc
change a combo to Afternoon and get a second set of 3 results inserted
12-9-2011 Afternoon etc
13-11-2011 Afternoon etc
14-12-2011 Afternoon etc

taking the master form details as set and appending to the table
(instead of updating)


code is

strSQL = "INSERT INTO tblTempSchedDates (" & _
"tscDate, " & _
"tscStartTime, tscEndTime, faculty_ID, f_clinicID,
discID, sessionID, " & _
"acc_yearID, acc_termID, tscNotes ) " & _
"Values(#" & datThis & "#, #" & Me.txtStartTime &
"#, #" & _
Me.txtEndTime & "#," & lngFacID & "," &
lngF_clinicID & "," & lngDisciplineID & ", " & _
lngSessionID & "," & lngAccYearID & "," &
lngAccTermID & "," & _
IIf(IsNull(varNotes), "Null", """" & varNotes &
"""") & ")"
' Debug.Print strSQL
' Stop

DB.Execute strSQL, dbFailOnError
End If
End If
Next
Else 'dates are there, just add the details from main form

strSQL = "Update tblTempSchedDates Set f_clinicID = " & lngF_clinicID
& ", faculty_ID = " & lngFacID & ",discID = " & lngDisciplineID & ",
sessionID = " & lngSessionID & ", acc_yearID = " & lngAccYearID & _
", acc_termID = " & lngAccTermID & ", tscStartTime =#" &
Me.txtStartTime & _
"#, tscEndTime = #" & Me.txtEndTime & "#"

This update the current records, and I want to append...

What I have tried so far a few variations to tray and replace the 2nd
strSQL:

Dim rs As Object
Dim tDate As Variant
tDate = Me.[sfrmTempScheduleEdit]![tscDate] ' this is the subform with
the dates
Set rs = Me.[sfrmTempScheduleEdit]![tscDate] ' this is not correct
and causing various errors
If Me.grpRepeats = 1 Then
With rs
Do While Not .EOF

strSQL = "INSERT INTO tblTempSchedDates (" & _
"tscDate, " & _
"tscStartTime, tscEndTime, faculty_ID, f_clinicID,
discID, sessionID, " & _
"acc_yearID, acc_termID, tscNotes ) " & _
"Values(#" & datThis & "#, #" & Me.txtStartTime &
"#, #" & _
Me.txtEndTime & "#," & lngFacID & "," &
lngF_clinicID & "," & lngDisciplineID & ", " & _
lngSessionID & "," & lngAccYearID & "," &
lngAccTermID & "," & _
IIf(IsNull(varNotes), "Null", """" & varNotes &
"""") & ")"
Debug.Print strSQL
DB.Execute strSQL, dbFailOnError

..MoveNext
Loop
End With
End If
Set rs = Nothing


I am missing something basic as this should be simpler than this.
Any suggestions would be appreciated
Thanks
John

Reply With Quote
  #2  
Old   
Patrick Finucane
 
Posts: n/a

Default Re: loop to take value from subform - 08-12-2011 , 05:02 PM






On Aug 12, 2:52*pm, flymo <fly... (AT) hotmail (DOT) com> wrote:
Quote:
Hello All
I am using Duane Hookums excellent recurring database file and I have
modified quite a bit.

I have come across a basic problem - the recurring code works great
when using a group of check boxes to generate a series of dates. The
code runs based on a value "group" in the main form:
If Me.grpRepeats = 2 Then
'runs code for recurring dates.

However when the choice is single dates these dates are entered
individually in a subform, the code updates a single date instead of
allowing me to add:
i add 12th, 13th & 14th dates (as below) 2011 - Morning , run the code
everything works ok, *I change a parameter 12th.13th & 14th *2011 *-
Afternoon and run again to create, the update over writes (as you
would expect.)

What I am need to do is add several single dates and loop through
12-9-2011 Morning etc
13-11-2011 Morning etc
14-12-2011 Morning etc
etc
change a combo to Afternoon and get a second set of 3 results inserted
12-9-2011 Afternoon etc
13-11-2011 Afternoon etc
14-12-2011 Afternoon etc

taking the master form details as set and appending to the table
(instead of updating)

code is

strSQL = "INSERT INTO tblTempSchedDates (" & _
* * * * * * * * * * "tscDate, " & _
* * * * * * * * * * "tscStartTime, tscEndTime, faculty_ID, f_clinicID,
discID, sessionID, " & _
* * * * * * * * * * "acc_yearID, acc_termID, tscNotes) " & _
* * * * * * * * * * "Values(#" & datThis & "#, #" & Me.txtStartTime &
"#, #" & _
* * * * * * * * * * *Me.txtEndTime & "#," & lngFacID & "," &
lngF_clinicID & "," & lngDisciplineID & ", " & _
* * * * * * * * * * *lngSessionID & "," & lngAccYearID & "," &
lngAccTermID & "," & _
* * * * * * * * * * IIf(IsNull(varNotes), "Null", """" & varNotes &
"""") & ")"
' * * * * * * * *Debug.Print strSQL
' * * * *Stop

* * * * * * * * DB.Execute strSQL, dbFailOnError
* * * * * * End If
* * * * * *End If
* * * * Next
* * *Else *'dates are there, just add the details from main form

strSQL = "Update tblTempSchedDates Set f_clinicID = " & lngF_clinicID
& ", faculty_ID = " & lngFacID & ",discID = " & lngDisciplineID & ",
sessionID = " & lngSessionID & ", acc_yearID = " & lngAccYearID & _
* * * * * * ", acc_termID = " & lngAccTermID & ", tscStartTime =#" &
Me.txtStartTime & _
* * * * * * "#, tscEndTime = #" & Me.txtEndTime & "#"

This update the current records, and I want to append...

What I have tried so far a few variations to tray and replace the 2nd
strSQL:

Dim rs As Object
Dim tDate As Variant
tDate = Me.[sfrmTempScheduleEdit]![tscDate] ' this is the subform with
the dates
Set rs = Me.[sfrmTempScheduleEdit]![tscDate] ' *this is not correct
and causing various errors
If Me.grpRepeats = 1 Then
With rs
Do While Not .EOF

*strSQL = "INSERT INTO tblTempSchedDates (" & _
* * * * * * * * * * "tscDate, " & _
* * * * * * * * * * "tscStartTime, tscEndTime, faculty_ID, f_clinicID,
discID, sessionID, " & _
* * * * * * * * * * "acc_yearID, acc_termID, tscNotes) " & _
* * * * * * * * * * "Values(#" & datThis & "#, #" & Me.txtStartTime &
"#, #" & _
* * * * * * * * * * *Me.txtEndTime & "#," & lngFacID & "," &
lngF_clinicID & "," & lngDisciplineID & ", " & _
* * * * * * * * * * *lngSessionID & "," & lngAccYearID & "," &
lngAccTermID & "," & _
* * * * * * * * * * IIf(IsNull(varNotes), "Null", """" & varNotes &
"""") & ")"
* * * * * * * * * * * * * * * * * * Debug.Print strSQL
* * * * * * * * * * DB.Execute strSQL, dbFailOnError

.MoveNext
Loop
End With
End If
Set rs = Nothing

I am missing something basic as this should be simpler than this.
Any suggestions would be appreciated
Thanks
John
You say setting the recordset causes problems. Maybe this will help
http://access.mvps.org/access/forms/frm0031.htm

You might want to look at "recordsource" in help as well.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.