Solved

Tempvars and afterupdate event of a checkbox

Posted on 2015-01-08
8
272 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 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
Independent Software Vendors: 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 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
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…

717 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