Solved

Tempvars and afterupdate event of a checkbox

Posted on 2015-01-08
8
269 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
  • 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 500 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 35

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

837 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