Expression for combo box

G

Guest

After updating a combo box, I would like to populate another field with
today's date.

Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" Then
Me![DATECLOSED] = Date

End If
End Sub


This works beautifully, however, I would like to add a few more If options.
I've tried:
Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" or "No Business" or "Lost to Comp" Then
Me![DATECLOSED] = Date

End If
End Sub

I also unsuccessfully tried:
Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" Then
Me![DATECLOSED] = Date

If ([STATUS]) = "No Business" Then
Me![DATECLOSED] = Date

End If
End Sub

Can someone help me, please.
 
T

tina

you need to use the correct syntax for the If...Then...Else statement. to
read up on it, and see a code example, go to the VBA procedure, put your
cursor on the If, and press F1. that takes you directly to the
If...Then...Else Statement topic in VBA Help. this little trick will work
for many statements, commands, etc, that you use in VBA coding, and is a
good way to learn.

i recommend that you learn about using the Else clause in If statements,
because many times you'll need it. in this particular case, you can either
use it, or use a single If statement with the following syntax, as

Private Sub CmbStatus_AfterUpdate()

If Me!STATUS = "Closed" _
Or Me!STATUS = "No Business" _
Or Me!STATUS = "Lost to Comp" Then
Me!DATECLOSED = Date
End If

End Sub

hth
 
G

Guest

It worked perfectly. As a self-taught Access programmer, I welcome any
advise. Thanks,

tina said:
you need to use the correct syntax for the If...Then...Else statement. to
read up on it, and see a code example, go to the VBA procedure, put your
cursor on the If, and press F1. that takes you directly to the
If...Then...Else Statement topic in VBA Help. this little trick will work
for many statements, commands, etc, that you use in VBA coding, and is a
good way to learn.

i recommend that you learn about using the Else clause in If statements,
because many times you'll need it. in this particular case, you can either
use it, or use a single If statement with the following syntax, as

Private Sub CmbStatus_AfterUpdate()

If Me!STATUS = "Closed" _
Or Me!STATUS = "No Business" _
Or Me!STATUS = "Lost to Comp" Then
Me!DATECLOSED = Date
End If

End Sub

hth


R Marko said:
After updating a combo box, I would like to populate another field with
today's date.

Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" Then
Me![DATECLOSED] = Date

End If
End Sub


This works beautifully, however, I would like to add a few more If options.
I've tried:
Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" or "No Business" or "Lost to Comp" Then
Me![DATECLOSED] = Date

End If
End Sub

I also unsuccessfully tried:
Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" Then
Me![DATECLOSED] = Date

If ([STATUS]) = "No Business" Then
Me![DATECLOSED] = Date

End If
End Sub

Can someone help me, please.
 
T

tina

you're welcome :)
and btw, you're not alone - like you, i am one of the many self-taught
developers in these newsgroups.


R Marko said:
It worked perfectly. As a self-taught Access programmer, I welcome any
advise. Thanks,

tina said:
you need to use the correct syntax for the If...Then...Else statement. to
read up on it, and see a code example, go to the VBA procedure, put your
cursor on the If, and press F1. that takes you directly to the
If...Then...Else Statement topic in VBA Help. this little trick will work
for many statements, commands, etc, that you use in VBA coding, and is a
good way to learn.

i recommend that you learn about using the Else clause in If statements,
because many times you'll need it. in this particular case, you can either
use it, or use a single If statement with the following syntax, as

Private Sub CmbStatus_AfterUpdate()

If Me!STATUS = "Closed" _
Or Me!STATUS = "No Business" _
Or Me!STATUS = "Lost to Comp" Then
Me!DATECLOSED = Date
End If

End Sub

hth


R Marko said:
After updating a combo box, I would like to populate another field with
today's date.

Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" Then
Me![DATECLOSED] = Date

End If
End Sub


This works beautifully, however, I would like to add a few more If options.
I've tried:
Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" or "No Business" or "Lost to Comp" Then
Me![DATECLOSED] = Date

End If
End Sub

I also unsuccessfully tried:
Private Sub CmbStatus_AfterUpdate()
If ([STATUS]) = "Closed" Then
Me![DATECLOSED] = Date

If ([STATUS]) = "No Business" Then
Me![DATECLOSED] = Date

End If
End Sub

Can someone help me, please.
 

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