WalkieTalkie
Technical User
Hi
I have a simple loop which I cannot make work - please tell me what I am doing wrong!
I have a list box (lstDate) in which the user selects the dates they want.
lstDate is bound to tblDate and has 4 columns; ID, Date, HolidayName, Outing.
Outing column is Yes/No.
If the user picks a date which is Yes for an outing, the amount they will be charged for the day will be $45. If they choose a day which does not have an outing, they will be charged $40. The aim of the code below is to populate tblTransaction with this info...
The first item works fine, but then the rest just have the same amount as the first, rather than changing according to whether or not it is an Outing day.
I'm still learning this stuff, but I 'm sure this should be relatively simple and I can't work out what I'm doing wrong. Thanks in advance for any help!
I have a simple loop which I cannot make work - please tell me what I am doing wrong!
I have a list box (lstDate) in which the user selects the dates they want.
lstDate is bound to tblDate and has 4 columns; ID, Date, HolidayName, Outing.
Outing column is Yes/No.
If the user picks a date which is Yes for an outing, the amount they will be charged for the day will be $45. If they choose a day which does not have an outing, they will be charged $40. The aim of the code below is to populate tblTransaction with this info...
Code:
Dim varItem As Variant
Dim txtTemp As String
Dim strSQL As String
Dim txtAmount As String
For Each varItem In Me.lstDate.ItemsSelected
txtTemp = txtTemp & Me.lstDate.ItemData(varItem) & ","
txtAmount = IIf(Me.lstDate.Column(3) = True, "-45.00", "-40.00")
Next
txtTemp = Left(txtTemp, Len(txtTemp) - 1)
strSQL = "INSERT INTO tblTransaction ( TransDate, KidAccountID, AttendStatus, TransactionType, Amount ) " & _
"SELECT tblDate.Date, " & Me![KidAccountID] & ", 1 , 11, " & txtAmount & " FROM tblDate " & _
" WHERE ID IN (" & txtTemp & ")"
Debug.Print strSQL 'for troubleshooting
CurrentDb.Execute strSQL, dbFailOnError
The first item works fine, but then the rest just have the same amount as the first, rather than changing according to whether or not it is an Outing day.
I'm still learning this stuff, but I 'm sure this should be relatively simple and I can't work out what I'm doing wrong. Thanks in advance for any help!