After Update

  • Thread starter PowerPoint Jedi
  • Start date
P

PowerPoint Jedi

hi,
Did a quick search and was unable to answer my question.

First off I am using Access 2003.

background.
I am making a from to enter testing status into a table. As it may take a
couple days to enter the data I wanted to use a Combo box with a Y/N
selection to determine if it is open or closed. When finished the user
should select yes and the this should trigger code to fill in the date closed
combo box with today's date

Here is what i currently have

Combo box #1
name - Closed

Combo box #2
name - closed date

Code for combo box #1 after update

Private Sub closed_AfterUpdate()
Forms![ERGR]![closed date] = Date
End Sub


This updates the closed date whether i select yes or no. so i tried this

Private Sub Closed_AfterUpdate()
If Forms![ERGR]![Closed] = yes Then Forms![ERGR]![closed date] = Date
Else: Forms![ERGR]![closed date] = Null
End If
End Sub

hoping it would use a null if not yes. When I run this i get the following
error

"compile error:

Else without if"


So could someone please tell me what I did wrong> I am new to this so be
gentle :)

Thanks in advance
 
D

Douglas J. Steele

Private Sub Closed_AfterUpdate()
If Forms![ERGR]![Closed] = yes Then
Forms![ERGR]![closed date] = Date
Else
Forms![ERGR]![closed date] = Null
End If
End Sub

or

Private Sub Closed_AfterUpdate()
If Forms![ERGR]![Closed] = yes Then Forms![ERGR]![closed date] = Date Else
Forms![ERGR]![closed date] = Null
End Sub

(where that's all one line)

I much prefer the first syntax!
 
D

Dirk Goldgar

Douglas J. Steele said:
Private Sub Closed_AfterUpdate()
If Forms![ERGR]![Closed] = yes Then
Forms![ERGR]![closed date] = Date
Else
Forms![ERGR]![closed date] = Null
End If
End Sub


But will this combo box have a value of yes? Or will it be "Yes"?
 
P

PowerPoint Jedi

Wow, thanks for the quick responses. I went for the first syntax and it
worked once i changed put yes in "".

Why was it that mine was not working, it seems the words were all correct so
where was my syntax wrong? I would like to understand so I don't have to
come back to ask the same question.

Is it that the else need to go on the end of the IF statement line?


Also the VB editor was adding in the semicolon after the Else each time.
 
D

Dirk Goldgar

PowerPoint Jedi said:
Wow, thanks for the quick responses. I went for the first syntax and it
worked once i changed put yes in "".

Why was it that mine was not working, it seems the words were all correct
so
where was my syntax wrong? I would like to understand so I don't have to
come back to ask the same question.

Is it that the else need to go on the end of the IF statement line?


Also the VB editor was adding in the semicolon after the Else each time.


That's because you were combining two different forms of the If statement.
The "single-line If" has the If, Then, and optional Else parts of the
statement all on one line, with no "End If" statement, like this:

If <condition> Then <statement(s)> [Else <other statement(s)]

The "block If" statement has the form

If <condition> Then
<statements>
Else
<other statements>
End If

Because what you had written didn't conform to either of those forms, the VB
editor didn't know how to parse it.
 
J

John W. Vinson

Why was it that mine was not working, it seems the words were all correct so
where was my syntax wrong?

You didn't have an IF block at all - it was updating the date in the
AfterUpdate event of the combo box, no matter what choice you made.
 
P

PowerPoint Jedi

Great guys thanks alot. That all really helped. Hopefully I won't be
bugging you too much more.
 

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