VBA help

alliandrina

Registered User.
Local time
Today, 00:19
Joined
Mar 9, 2011
Messages
13
I could use some help with VBA. To be honest, I don't know it and didn't write what I am about to post. I keep getting an error message that says 'invalid use of null"

Private Sub Form_BeforeUpdate(cancel As Integer)

Dim varW, varX, varY As Variant

If IsNull([CreateDate]) Then
varW = DLookup("[schoolID]", "tblteachers", "[name]= '" + cmbTeacher.Value + "'")
varX = DLookup("[ID]", "tblteachers", "[name]= '" + cmbTeacher.Value + "'")
[UserName] = CurrentUser()
[CreateDate] = Date + Time
[ModifyDate] = Date + Time
[SchoolID] = varW
[TeacherID] = varX
[Grade] = cmbGrade.Value
[SurveyDate] = txtFormDate.Value
[FormGroup] = CStr([TeacherID]) + [Grade] + CStr([SurveyDate])
[VisitDate] = txtVisitDate
[VisitTime] = txtVisitTime
[Duration] = txtDuration
txtSum.Requery
txtSumM.Requery
txtSumF.Requery
varY = DMax("[Rownumber]", "tblTeacherPresurvey", "[formgroup]= '" + [FormGroup] + "'")

[RowNumber] = IIf(IsNull(varY), 1, varY + 1)
Else
[ModifyDate] = Date + Time
End If


End Sub

The debugger highlights what's in marked in red. Is there something wrong with it? Do you need more information?
 
Check if you have data in all the fields on the highlihted line of code.
This isn't good enough for vba
Code:
If IsNull([CreateDate]) Then
Try
Code:
If IsNull([CreatedDate]) or CreatedDate = "" Then
or shorter version
Code:
If CreatedDate & "" = "" Then

You need to check for an Empty String as well as Null.
 

Users who are viewing this thread

Back
Top Bottom