VB Code

A

Armin

I've been trying to make this code work.What I'm trying to
do is if the Expdate was NULL before update it should run
the Reminder function, else it should update the ExpDate.I
was able to get it to work with

If slRecordsAffected = 0 Then
Reminder

However, I would like to do it without running the SQL if
the expdate field is empty.Following code does not work.

Thanks in advance

Armin

Private Sub Expdate_AfterUpdate()
Dim strSQL As String, cn As ADODB.Connection,
slRecordsAffected As Long

If (Me!Expdate.BeforeUpdate) = Null Then

Reminder ' FUNCTION THAT ADDS A REMINDER

Else

strSQL = " UPDATE tblreminder SET " _
& "tblreminder.remdate = '" & Me.Expdate & " '," _
& "tblreminder.note = 'Deadline for this
application is on " & Me.Expdate & "'" _
& "WHERE [ApplicID]= " & Me.ApplicID & " AND
[remapplic] = -1"


Set cn = CurrentProject.Connection
cn.Execute strSQL, slRecordsAffected


'If slRecordsAffected = 0 Then
'Reminder
'Else

MsgBox "Expiration date has been updated!", ,
cn.Close
End If
End Sub
 
B

Byron

Place the following code in the BeforeUpdate event of the
control. It will check for the null value in the control.

if isnull(Me!Expdate) then
'here run whatever code
endif
 
F

fredg

I've been trying to make this code work.What I'm trying to
do is if the Expdate was NULL before update it should run
the Reminder function, else it should update the ExpDate.I
was able to get it to work with

If slRecordsAffected = 0 Then
Reminder

However, I would like to do it without running the SQL if
the expdate field is empty.Following code does not work.

Thanks in advance

Armin

Private Sub Expdate_AfterUpdate()
Dim strSQL As String, cn As ADODB.Connection,
slRecordsAffected As Long

If (Me!Expdate.BeforeUpdate) = Null Then

Reminder ' FUNCTION THAT ADDS A REMINDER

Else

strSQL = " UPDATE tblreminder SET " _
& "tblreminder.remdate = '" & Me.Expdate & " '," _
& "tblreminder.note = 'Deadline for this
application is on " & Me.Expdate & "'" _
& "WHERE [ApplicID]= " & Me.ApplicID & " AND
[remapplic] = -1"


Set cn = CurrentProject.Connection
cn.Execute strSQL, slRecordsAffected

'If slRecordsAffected = 0 Then
'Reminder
'Else

MsgBox "Expiration date has been updated!", ,
cn.Close
End If
End Sub

Use IsNull() not = Null.

If isNull([ExpDate]) Then
Some Code Here
Else
Something else here
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top