?
Solved

Tempvars and afterupdate event of a checkbox

Posted on 2015-01-08
8
Medium Priority
?
276 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 38

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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