Carmen
Registered User.
- Local time
- Today, 18:55
- Joined
- Nov 30, 2001
- Messages
- 58
I have written this function to automatically "calculate" a field based on two other fields. Therefore, CalcSecID is a string. This code works perfectly.....
Option Compare Database
Dim yr
Dim sem
Dim ModID
Dim session
Function CalcSecID()
'capture the year of session 1 date as yr and label the fall and _
spring semesters according to the month of session 1. Combine _
yr, sem, and module id to create the section ID field.
ModID = Forms!frmClasses!ModuleID
session = Forms!frmClasses!Session1
yr = Year(session)
If (DatePart("m", [session]) <= 6) Then
sem = "SP"
ElseIf (DatePart("m", [session]) >= 7) Then
sem = "FA"
End If
CalcSecID = yr & sem & "M" & ModID & "-" & 1
Forms!frmClasses!Text28 = CalcSecID
End Function
So you can see that my field ends up with the format "2001FAM3-1" (for example). Now I need to increase this number by one for each record. So the next record would be "2001FAM3-2", etc... I have created the following For Each...Next Loop that I would call in the function:
Private Sub SecIDLoop()
Dim CalcSecID As Variant
'to add one to each calcsecid
For Each CalcSecID In frmClasses
CalcSecID = CalcSecID + 1
Next
End Sub
However I keep getting a type mismatch message no matter what I do. I've tried CalcSecID=Val(CalcSecID) and that doesn't work either. By the way, the underlying data type in the associated table is text. Does someone please have a suggestion? Thanks!
Option Compare Database
Dim yr
Dim sem
Dim ModID
Dim session
Function CalcSecID()
'capture the year of session 1 date as yr and label the fall and _
spring semesters according to the month of session 1. Combine _
yr, sem, and module id to create the section ID field.
ModID = Forms!frmClasses!ModuleID
session = Forms!frmClasses!Session1
yr = Year(session)
If (DatePart("m", [session]) <= 6) Then
sem = "SP"
ElseIf (DatePart("m", [session]) >= 7) Then
sem = "FA"
End If
CalcSecID = yr & sem & "M" & ModID & "-" & 1
Forms!frmClasses!Text28 = CalcSecID
End Function
So you can see that my field ends up with the format "2001FAM3-1" (for example). Now I need to increase this number by one for each record. So the next record would be "2001FAM3-2", etc... I have created the following For Each...Next Loop that I would call in the function:
Private Sub SecIDLoop()
Dim CalcSecID As Variant
'to add one to each calcsecid
For Each CalcSecID In frmClasses
CalcSecID = CalcSecID + 1
Next
End Sub
However I keep getting a type mismatch message no matter what I do. I've tried CalcSecID=Val(CalcSecID) and that doesn't work either. By the way, the underlying data type in the associated table is text. Does someone please have a suggestion? Thanks!