Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

After Update Code

Posted on 2006-06-29
12
Medium Priority
?
219 Views
Last Modified: 2008-03-17
Hello,

I'm not sure how to write this code.

Here's the code I have in place,...

Private Sub txtAttendanceSubject_AfterUpdate()
Me.txtAttendanceNote = 1
End Sub

But here's what I would like,...

Private Sub txtAttendanceSubject_AfterUpdate()
Me.txtAttendanceNote = Null
IF txtAttendanceSubject = Any Value, then = 1
IF txtAttendanceSubject = No Value, then = Null

So basically, if txtAttendanceSubject equals a value of any kind, txtAttendanceSubject will ALWAYS = 1

But if there's nothing in txtAttendanceSubject, OR the value has since been removed, THEN it needs to = Null
End Sub
0
Comment
Question by:xp310
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
12 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17011531
The AfterUpdate event fires AFTER you UPDATE, so if you want to impliment code that changes the value, you'll want to do it in BeforeUpdate, like this:

Private Sub txtAttendanceSubject_BeforeUpdate(Cancel as Integer)

Me.txtAttendanceNote = Null
IF Nz(Me.txtAttendanceSubject, 'Wahoo') <> "Wahoo"
    Me.txtAttendanceSubject = 1
else
    Me.txtAttendanceSubject = NULL
end if

End Sub
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 17011536
(slight correction, need double quotes)

IF Nz(Me.txtAttendanceSubject, "Wahoo") <> "Wahoo"   '<-- Replace "Wahoo" with whatever floats your boat
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17011537
Private Sub txtAttendanceSubject_AfterUpdate()
    if NZ(Me.txtAttendanceSubject ,"") = "" then Me.txtAttendanceNote = Null else Me.txtAttendanceNote = 1
End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 17011564
Oopps copy/paste wrong field?

Private Sub txtAttendanceSubject_AfterUpdate()
    if NZ(Me.txtAttendanceSubject ,"") = "" then Me.txtAttendanceSubject = Null else Me.txtAttendanceSubject = 1
End Sub

but tell me, do u intentionally change Subject to 1 if a value has been entered?
If u do the above, it will call the AfterUpdate function again


0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17011607
Just curious if u are always going to set the Subject to 1 or nothing, why dont u create some kind of checkbox instead

0
 

Author Comment

by:xp310
ID: 17011743
Jim,

I tried your code in the Before Update - but for my example, I can't tie it to a specific word.  So I replaced "wahoo" with "".  And in doing that, the code doesn't work & highlights that specific row I changed.

As for the before & after update - I think I have a very different understanding how those events work.  To me, it would make sense to put it in the after update.  If the code runs "Before" then how is it going to determine the correct answer.  It would make sense that it would run "After" to determine if a value of any kind has been entered.

Eh, like I said...  I'm sure my sense of what those events do is complete screwed up.  :-)

Rockiroads,

I tried your code, but it didn't work for me it just resulted in errors.  As for your comment about me changing the values - well your codes are backwards I think.

This is basically what I want...

"IF txtAttendanceSubject = ANY VALUE then txtAttendanceNote will = 1"

So, txtAttendanceNote only signifies a value has been entered into the subject field.  if there's no 1, then there shouldn't be a subject.
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 17015144
This one checks that subject isn't null or blank. If that's true, then note = 1 else note = null

Private Sub txtAttendanceSubject_AfterUpdate()

If Not Nz(me.txtAttendanceSubject.value) = ""  then
    me.txtAttendanceNote.value = 1
else
    me.txtAttendanceNote.value = Null
end if

End Sub
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17015745
xp310
this is what I thought, Im sure it was a typo

my first post, this should do what u want

Private Sub txtAttendanceSubject_AfterUpdate()
    if NZ(Me.txtAttendanceSubject ,"") = "" then Me.txtAttendanceNote = Null else Me.txtAttendanceNote = 1
End Sub


did this not work?

my 2nd post was a reflection of what u said in your initial question, but then I queried this - u wanted to update the subject. I thought this was wrong.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 17019875
<no comment>

Nic;o)
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 17020510
Hello All,
Rocki's solution works...do not accept mine as answer as I was not first.
J
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question