473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Resetting Yes/No value

4
I'm relatively new to VBA coding, but in the project I'm working on, I've got a Yes/No option to make certain people active and others not. I can't seem to get the reset to the No value to work and this is something the user needs to be able to do. Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Inactive_Click()
  2. On Error GoTo Err_Inactive_Click
  3. Dim MsgResult As VbMsgBoxResult
  4. Dim MySQL As String
  5.  
  6.      MsgResult = MsgBox("Are you sure you want to make ALL Candidates Inactive?", vbYesNo, "Make Candidates Inactive?")
  7. If (MsgResult = vbYes) Then
  8.  
  9. MySQL = "UPDATE CandidateInformation SET CandidateInformation.ActiveCandidate = False WHERE (((CandidateInformation.ActiveCandidate)= True))"
  10.  
  11. DoCmd.RunSQL MySQL
  12.  
  13. End If
  14.  
  15. Exit_Inactive_Click:
  16.     Exit Sub
  17.  
  18. Err_Inactive_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_Inactive_Click
  21.  
  22. End Sub
  23.  
  24.  
Thanks for any help/feedback!
Mar 2 '07 #1
7 4459
MSeda
159 Expert 100+
the yes/no message box actually returns the integer 6 for yes and 7 for no.
Change the vbYes in your condition to 6 and your code should work.

when in doubt insert a message box that displays the variable after setting the value of a variable just to make sure what you think should happen is really happening.
Mar 2 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
the yes/no message box actually returns the integer 6 for yes and 7 for no.
Change the vbYes in your condition to 6 and your code should work.

when in doubt insert a message box that displays the variable after setting the value of a variable just to make sure what you think should happen is really happening.
As a follow on to this change the variable to an integer.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim MsgResult As Integer
Mar 2 '07 #3
Macros
4
Thanks to you both for the fixes. I'm running into another problem now where it's asking me to enter a parameter value and no matter what I try, I get a message of 'operation must use an updateable query. Now I do have this pointed at a table, but I've also tried it using a query with that field and it still gives me the same messages. (Using Access 2000)

Here's the code with the changes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Inactive_Click()
  2. On Error GoTo Err_Inactive_Click
  3. Dim MsgResult As Integer
  4. Dim MySQL As String
  5.  
  6.      MsgResult = MsgBox("Are you sure you want to make ALL Candidates Inactive?", vbYesNo, "Make Candidates Inactive?")
  7. If (MsgResult = 6) Then
  8.  
  9. MySQL = "UPDATE CandidateInformation SET CandidateInformation.Active_Candidate = False WHERE (((CandidateInformation.Active_Candidate)= True))"
  10.  
  11. DoCmd.RunSQL MySQL
  12.  
  13. End If
  14.  
  15. Exit_Inactive_Click:
  16.     Exit Sub
  17.  
  18. Err_Inactive_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_Inactive_Click
  21.  
  22. End Sub
  23.  
Mar 3 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
Thanks to you both for the fixes. I'm running into another problem now where it's asking me to enter a parameter value and no matter what I try, I get a message of 'operation must use an updateable query. Now I do have this pointed at a table, but I've also tried it using a query with that field and it still gives me the same messages. (Using Access 2000)

Here's the code with the changes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Inactive_Click()
  2. On Error GoTo Err_Inactive_Click
  3. Dim MsgResult As Integer
  4. Dim MySQL As String
  5.  
  6.      MsgResult = MsgBox("Are you sure you want to make ALL Candidates Inactive?", vbYesNo, "Make Candidates Inactive?")
  7. If (MsgResult = 6) Then
  8.  
  9. MySQL = "UPDATE CandidateInformation SET CandidateInformation.Active_Candidate = False WHERE (((CandidateInformation.Active_Candidate)= True))"
  10.  
  11. DoCmd.RunSQL MySQL
  12.  
  13. End If
  14.  
  15. Exit_Inactive_Click:
  16.     Exit Sub
  17.  
  18. Err_Inactive_Click:
  19.     MsgBox Err.Description
  20.     Resume Exit_Inactive_Click
  21.  
  22. End Sub
  23.  
Since you are setting all CandidateInformation.Active_Candidate to False you don't need the where statement so delete it.

Mary
Mar 3 '07 #5
NeoPa
32,556 Expert Mod 16PB
I can't see anything wrong with your code or your SQL (Since the variable MsgResult was converted to Integer - the only bug I could see).
I did notice though, that while you made no comment about it, you changed the name of the field between posts. Make sure whatever you use reflects the absolutely accurate name of the field.
I suggest you change your MySQL line to :
Expand|Select|Wrap|Line Numbers
  1. MySQL = "UPDATE CandidateInformation " & _
  2.         "SET Active_Candidate=False " & _
  3.         "WHERE Active_Candidate=True"
All the rest is extraneous cr*p provided gratuitously by MS Access.
I would keep the WHERE clause, as it will execute more efficiently that way.
vbYes is also a more readable version than 6. If it had solved your problem it may have been worth keeping but in the circumstances...
Mar 3 '07 #6
Macros
4
Thanks for the posts. I ended up seeing my mistake after walking away for a day. I had the field name set in the Table wrong. So fixed that and it worked like a charm! Thanks for all the help!
Mar 5 '07 #7
NeoPa
32,556 Expert Mod 16PB
Glad to hear you got it resolved. I wondered if it may come back to that somehow.
Mar 5 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Job Lot | last post by:
On form load my datagrid gets populated with values from database table. How can I reset values in my DataGrid to 0 on click of a button? thanks
14
by: Bobby | last post by:
I have this line, at this time the value of Session("Login") is 1: Response.Write "<a href=" & Request("script_name") & _ "?action=show&o=" & rsCustOrders("OrderID") & _ ">" &...
2
by: MickG | last post by:
I think that this should be reasonably easy but it is proving to be hugely difficult. I am wanting to reset the form to all the original values when I submit the form. Here is the select box...
2
by: vihang | last post by:
I have a code which is implementing a stack using array.. the code is $ nl pb4.c 1 #include <stdio.h> 2 char stack; 3 void push(char i,int top) 4 { 5 stack=i; 6 }
8
by: Nathan Sokalski | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. After the file is successfully submitted, I want the field to be reset so that the user knows the file was...
4
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I...
8
by: Kevin | last post by:
I'm using a form where users can input a bunch of info into unbound text controls that are used in series of calculations. At the bottom is a "reset" button. I want to clear out all of the user...
2
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hi Everyone. I was using the following code in VB6, but am in the middle of converting the app to VB.Net 2005. He is the code Private Sub ClearAll() On Error GoTo Error_Routine Call...
1
by: hai.mailbox | last post by:
Hello everyone, I have a small problem with javascript below: <p>Slider Test</p> <div class="slider" id="slider1" tabIndex="1"> <input class="slider-input" id="slider1_input"/> </div> <form...
4
by: Rajneesh Chellapilla | last post by:
I wrote this program. Its kinda of strange when I make a reset function reset(){c=0} its doest reset the setTimeout. However if I directly pass c=0 to the onclick button it does reset the timer. What...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.