deejayquai
New member
- Local time
- Today, 21:22
- Joined
- Mar 26, 2007
- Messages
- 4
Hello
I'm trying to append a series of values into fields from one table to
another based on highlighted rows in a multi-select listbox. I'm
stuck however when I need to append a couple of fields which is based
on a Dlookup kind of function and an IF function.
My basic code is based on:
For Each lbl1ID In lstStudents.ItemsSelected
DoCmd.RunSQL "INSERT into tblGroupMembers ([Student ID], [Group
Code ID], [Surname], [First Name], [Class Year],[Initials],[Form],
[SEN Status],[Gifted/Talented Status],[Gender],[Current WL Level])" _
& "VALUES (""" & lstStudents.Column(0, lbl1ID) _
& """,""" & [Group Code ID] _
& """,""" & lstStudents.Column(1, lbl1ID) _
& """,""" & lstStudents.Column(2, lbl1ID) _
& """,""" & lstStudents.Column(6, lbl1ID) _
& """,""" & Nz(lstStudents.Column(3, lbl1ID), Null) _
& """,""" & lstStudents.Column(7, lbl1ID) _
& """,""" & lstStudents.Column(4, lbl1ID) _
& """,""" & lstStudents.Column(5, lbl1ID) _
& """,""" & lstStudents.Column(8, lbl1ID) _
& """,""" & [cboAchieve] & """)"
Next:
Works fine. But I now need to insert into two new fields- [LY Effort]
and [LY Attainment] using a dlookup function based on the [Student ID]
value in the list box (ie Column 0) and the [Class Year] value in the
list box (ie Column 6) which has to be -1 (ie the previous year!).
Something like this-
[LY Effort] = DLookup("[Overall Effort]", "tblGroupMembers", "[Student
ID] = lstStudents.Column(0,lbl1ID}" And "[Class Year] =
lstStudents.Column(6,lbl1ID)-1")
[LY Attainment]= = DLookup("[Overall Attaiment]", "tblGroupMembers",
"[Student ID] = lstStudents.Column(0,lbl1ID}" And "[Class Year] =
lstStudents.Column(6,lbl1ID)-1")
The final bit is that I don't want to append the [LY Effort] or [LY
Attainment] into the new record if the [Class Year] -1 value is 7 or
if it is null (as the records won't exist!). I need some kind of
error transaction handler that lets those rows highlighted in the list
box pass through up to the point where the rule is broken.
Something like this-
If lstStudents(6,lbl1ID)-1 = 7 or IsNull Then Stop Transaction etc etc
Simple eh!
Grateful for anyones time and patience on this. I have tried
searching very hard and attempted many times to work this out before
posting here. I've used a series of variables and split the For Each
Next routine through a If Then Else but I think I'm out of my depth on
this one!
regards
David
I'm trying to append a series of values into fields from one table to
another based on highlighted rows in a multi-select listbox. I'm
stuck however when I need to append a couple of fields which is based
on a Dlookup kind of function and an IF function.
My basic code is based on:
For Each lbl1ID In lstStudents.ItemsSelected
DoCmd.RunSQL "INSERT into tblGroupMembers ([Student ID], [Group
Code ID], [Surname], [First Name], [Class Year],[Initials],[Form],
[SEN Status],[Gifted/Talented Status],[Gender],[Current WL Level])" _
& "VALUES (""" & lstStudents.Column(0, lbl1ID) _
& """,""" & [Group Code ID] _
& """,""" & lstStudents.Column(1, lbl1ID) _
& """,""" & lstStudents.Column(2, lbl1ID) _
& """,""" & lstStudents.Column(6, lbl1ID) _
& """,""" & Nz(lstStudents.Column(3, lbl1ID), Null) _
& """,""" & lstStudents.Column(7, lbl1ID) _
& """,""" & lstStudents.Column(4, lbl1ID) _
& """,""" & lstStudents.Column(5, lbl1ID) _
& """,""" & lstStudents.Column(8, lbl1ID) _
& """,""" & [cboAchieve] & """)"
Next:
Works fine. But I now need to insert into two new fields- [LY Effort]
and [LY Attainment] using a dlookup function based on the [Student ID]
value in the list box (ie Column 0) and the [Class Year] value in the
list box (ie Column 6) which has to be -1 (ie the previous year!).
Something like this-
[LY Effort] = DLookup("[Overall Effort]", "tblGroupMembers", "[Student
ID] = lstStudents.Column(0,lbl1ID}" And "[Class Year] =
lstStudents.Column(6,lbl1ID)-1")
[LY Attainment]= = DLookup("[Overall Attaiment]", "tblGroupMembers",
"[Student ID] = lstStudents.Column(0,lbl1ID}" And "[Class Year] =
lstStudents.Column(6,lbl1ID)-1")
The final bit is that I don't want to append the [LY Effort] or [LY
Attainment] into the new record if the [Class Year] -1 value is 7 or
if it is null (as the records won't exist!). I need some kind of
error transaction handler that lets those rows highlighted in the list
box pass through up to the point where the rule is broken.
Something like this-
If lstStudents(6,lbl1ID)-1 = 7 or IsNull Then Stop Transaction etc etc
Simple eh!
Grateful for anyones time and patience on this. I have tried
searching very hard and attempted many times to work this out before
posting here. I've used a series of variables and split the For Each
Next routine through a If Then Else but I think I'm out of my depth on
this one!
regards
David