Solved

Tempvars and afterupdate event of a checkbox

Posted on 2015-01-08
8
258 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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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
 
LVL 34

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

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

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

Expert Comment

by:Rey Obrero
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now