Object Required Error

G

Guest

I read SandyR's post but could not solve my problem.

In a form, I am trying to make the user enter a date of employee transfer or
seperation (Unassignment). If the user checks either the Transfer box or
Archive box and does not enter the date, I want a message telling the user to
enter the date before saving the record. I get a Run-time Error "424" on this
line of code >If Me.Archive = True And Me.Unassignment_Date Is Null Then<
This code is in the Form, Before Update, Event.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMessage As String

strMessage = "You must enter the Unassignment Date before you continue."

If Me.Archive = True And Me.Unassignment_Date Is Null Then
MsgBox strMessage, vbExclamation, "Missing Unassignment Date"
Cancel = True

End If
End Sub

*****************
On the following version I get an error "Compile Error, Object Required".
The complaining line of code is >Set dtmUpdate =<

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strMessage As String
Dim dtmUpdate As Date

Set dtmUpdate = Me.Unassignment_Date

strMessage = "You must enter the Unassignment Date before you continue."


If Me.Archive = True And dtmUpdate Is Null Then
MsgBox strMessage, vbExclamation, "Missing Unassignment Date"
Cancel = True

End If
End Sub

What do you think?

Thanks,

Dennis
 
R

Rick Brandt

Don said:
I read SandyR's post but could not solve my problem.

In a form, I am trying to make the user enter a date of employee transfer or
seperation (Unassignment). If the user checks either the Transfer box or
Archive box and does not enter the date, I want a message telling the user to
enter the date before saving the record. I get a Run-time Error "424" on this
line of code >If Me.Archive = True And Me.Unassignment_Date Is Null Then<
This code is in the Form, Before Update, Event.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMessage As String

strMessage = "You must enter the Unassignment Date before you continue."

If Me.Archive = True And Me.Unassignment_Date Is Null Then
MsgBox strMessage, vbExclamation, "Missing Unassignment Date"
Cancel = True

End If
End Sub

*****************
On the following version I get an error "Compile Error, Object Required".
The complaining line of code is >Set dtmUpdate =<

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim strMessage As String
Dim dtmUpdate As Date

Set dtmUpdate = Me.Unassignment_Date

strMessage = "You must enter the Unassignment Date before you continue."


If Me.Archive = True And dtmUpdate Is Null Then
MsgBox strMessage, vbExclamation, "Missing Unassignment Date"
Cancel = True

End If
End Sub

What do you think?

Is Null is for SQL. In VBA code you use the IsNull() function.
 

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