If value selected in one field the enter date in another field

D

Don

I have a field in a subform called Status. When I select statusId 3 I want to
automatically have Access enter todays date in the Due Date field. I am
trying the below code but do not understand what the error message is telling
me to do.

Private Sub Combo44_BeforeUpdate(Cancel As Integer)

Dim stDate As String
Dim ingCheck As Long ' Error here "Object Required"

Set stDate = Me.Due_Date
Set lngCheck = Me.Status

If lngCheck Is "3" Then
stDate = Now()

End If

End Sub

What can I do to make this work?



Thanks,

Dennis
 
T

tina

the problem is the "Set" reserved word. you only use the word Set to set the
value of an object variable; what you want to do here is just assign a value
to an ordinary variable.

also, i'm wondering why you're 1) saving a date/time value in a String data
type variable, and 2) why you're not assigning the date/time value to the
field in the form's RecordSource, but just assigning it to the stDate
variable - the variable will lose that value as soon as the procedure ends.
if you don't have a reason for either 1 or 2, suggest the following, as

If Me!Status = 3 Then
Me!DueDate = Now
End If

i personally wouldn't bother with variables at all for such simple code.
also, unless the Status field is a Text data type, you won't need to enclose
the 3 value in double quotes. and note no closed parentheses on Now; you
don't use them in VBA, only when you're calling the Now() function outside
of a module do you need the parens.

hth
 
D

Don

It worked!
--
Thanks,

Dennis


tina said:
the problem is the "Set" reserved word. you only use the word Set to set the
value of an object variable; what you want to do here is just assign a value
to an ordinary variable.

also, i'm wondering why you're 1) saving a date/time value in a String data
type variable, and 2) why you're not assigning the date/time value to the
field in the form's RecordSource, but just assigning it to the stDate
variable - the variable will lose that value as soon as the procedure ends.
if you don't have a reason for either 1 or 2, suggest the following, as

If Me!Status = 3 Then
Me!DueDate = Now
End If

i personally wouldn't bother with variables at all for such simple code.
also, unless the Status field is a Text data type, you won't need to enclose
the 3 value in double quotes. and note no closed parentheses on Now; you
don't use them in VBA, only when you're calling the Now() function outside
of a module do you need the parens.

hth
 

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