Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Tempvars and afterupdate event of a checkbox

Posted on 2015-01-08
8
Medium Priority
?
279 Views
Last Modified: 2015-01-08
I'm using the following code in an afterupdate event of a checkbox on a form.  In either case when I check or uncheck the checkbox the msgbox returns a "0".  What is wrong with the code?

Private Sub chkboxTurnOffEmailAlerts_AfterUpdate()

Dim myEmailAlert As Integer

    If Me.chkboxTurnOffEmailAlerts = True Then
        TempVars.Add "myEmailAlert", Me.chkboxTurnOffEmailAlerts.Value
        MsgBox myEmailAlert
    End If
    
    If Me.chkboxTurnOffEmailAlerts = False Then
        TempVars.Remove "myEmailAlert"
        MsgBox myEmailAlert
    End If

End Sub

Open in new window

0
Comment
Question by:SteveL13
[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
  • 5
  • 2
8 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40538706
what about if you do this

Private Sub chkboxTurnOffEmailAlerts_AfterUpdate()

Dim myEmailAlert As Integer

    If Me.chkboxTurnOffEmailAlerts = True Then
        TempVars.Add "myEmailAlert", Me.chkboxTurnOffEmailAlerts.Value
        MsgBox myEmailAlert
 
        Else
 
        TempVars.Remove "myEmailAlert"
        MsgBox myEmailAlert
    End If

End Sub
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40538710
what about if you do this

Private Sub chkboxTurnOffEmailAlerts_AfterUpdate()

Dim myEmailAlert As Integer

    If Me.chkboxTurnOffEmailAlerts = True Then
        TempVars.Add "myEmailAlert", Me.chkboxTurnOffEmailAlerts.Value

        MsgBox TempVars!myEmailAlert
 
        Else
 
        TempVars.Remove "myEmailAlert"
        MsgBox TempVars!myEmailAlert
    End If
End Sub
0
 

Author Comment

by:SteveL13
ID: 40538713
Both are still "0"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:PatHartman
ID: 40538723
I don't think you want to make the tempvar appear and disappear.  You want to declare it and then set its value to true or false.  If you use the tempvar later in code and it isn't instantiated, you will get a runtime error.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40538744
try using the click event of the checkbox

Private Sub chkboxTurnOffEmailAlerts_Click()
Dim myEmailAlert As Integer

    If Me.chkboxTurnOffEmailAlerts = True Then
        TempVars.Add "myEmailAlert", Me.chkboxTurnOffEmailAlerts.Value

        MsgBox TempVars!myEmailAlert
 
        Else
 
        TempVars.Remove "myEmailAlert"
        MsgBox Nz(TempVars!myEmailAlert, 0)
    End If
End Sub
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40538761
test this, it works with onclick and afterupdate event of the checkbox

there mustbe something wroong with form
dbCheckbox.accdb
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40538763
there must be something wrong with your form
0
 

Author Comment

by:SteveL13
ID: 40538776
Rey,

Sorry.. .you 2nd suggestion DID work after all.:

Private Sub chkboxTurnOffEmailAlerts_AfterUpdate()

 Dim myEmailAlert As Integer

     If Me.chkboxTurnOffEmailAlerts = True Then
         TempVars.Add "myEmailAlert", Me.chkboxTurnOffEmailAlerts.Value

         MsgBox TempVars!myEmailAlert
  
         Else
  
         TempVars.Remove "myEmailAlert"
         MsgBox TempVars!myEmailAlert
     End If
 End Sub 

Open in new window

0

Featured Post

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.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

649 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