473,386 Members | 1,819 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,386 software developers and data experts.

VBA to change a field based on a if then statement

5
I have a form that should a count of days exceed 25 a email should be sent out and then a box checked to acknowledge that it was sent out. I can get the first part but checking the box is causing me problems. Can anyone help?
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     If (Forms!frmRetailProductionLogOpenSplit!RegBDays > 25 And Forms!frmRetailProductionLogOpenSplit!RegBComplianceNotified = 0) Then
  3.         DoCmd.SendObject acReport, "rptRetailProductionLogRegB", "PDFFormat(*.pdf)", "john.doe@bank.com", "", "", "Reg B", """Check the Reg B status on the attached Report"".", False, ""
  4. Me!RegBComplianceNotified = 1
  5.     End If
  6.  
  7. End Sub
Dec 28 '11 #1

✓ answered by Stewart Ross

Assuming that control RegBComplianceNotified is a checkbox, you need to set it to the boolean value True (which is represented as -1, not 1), as follows:

Expand|Select|Wrap|Line Numbers
  1. Me!RegBComplianceNotified = True
or, equivalently,

Expand|Select|Wrap|Line Numbers
  1. Me!RegBComplianceNotified = -1
-Stewart

9 1777
Stewart Ross
2,545 Expert Mod 2GB
Assuming that control RegBComplianceNotified is a checkbox, you need to set it to the boolean value True (which is represented as -1, not 1), as follows:

Expand|Select|Wrap|Line Numbers
  1. Me!RegBComplianceNotified = True
or, equivalently,

Expand|Select|Wrap|Line Numbers
  1. Me!RegBComplianceNotified = -1
-Stewart
Dec 28 '11 #2
HBCPH
5
I tried True and "Yes" and now have tried the -1 but I get the message "You can't assign a value to this object". If I run VBA to check the box by itself it works fine but not in combination.
Dec 28 '11 #3
NeoPa
32,556 Expert Mod 16PB
HBCPH:
"You can't assign a value to this object".
Therein lies your problem then. What is it about the design of your form that precludes this control from accepting a value? We cannot tell you something that you haven't given us any clue to first.
Dec 28 '11 #4
HBCPH
5
I wish I knew the answer to that, as I mentioned if I run VBA to only check the box it works fine but if I try to add it to the VBA that sends the email it doesn't work. Separately they both will run. But I need them both to run if they meet the criteria.
Dec 28 '11 #5
Mihail
759 512MB
Place line 4 before line 3
Dec 29 '11 #6
Killer42
8,435 Expert 8TB
I've run into this error numerous times (though it was a long time ago, not working much with Access these days). As far as I can recall, I was basically unable to touch controls from my code unless they had the focus. So I had to set focus to the control, then set the value.

Might be worth a try, at least.

P.S. After reading "Place line 4 before line 3" (I had this page open for a few hours, so I didn't see that before posting my reply) I'm thinking it might just be that the right form has to have focus, not specifically the control.
Dec 29 '11 #7
Mihail
759 512MB
Yes. This was the idea. Is this working ?
Dec 29 '11 #8
slenish
283 100+
You could do a work around. Create an unbound text box hidden on your form. Then when the check box is clicked set the text box value to 1 or True or what ever you want. Then have your code check the hidden text box for the value instead of the check box itself for the value and see if that works. After the email is sent then clear the text box of the value.
Dec 29 '11 #9
HBCPH
5
I finally got it to run, it seems to have something to do with which event triggered the VBA. I moved it to "On Lod" and it ran fine. Thank You to everyone for trying to help.
Dec 29 '11 #10

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

Similar topics

1
by: Brian Jorgenson | last post by:
Is it possible to add a If-then statement in a query? For example, If field B is greater then field A, then field B = something else. I am creating a class schedule. My class size's are 5 people...
3
by: sck10 | last post by:
Hello, I am trying to use an If Then statement inside of a repeater control. However, I am getting the following error: Expression expected. Any help would be appreciated. Thanks in...
1
by: jburris | last post by:
I am completely new to VBA. I am trying to update a yes/no box in a subform based on a value that I call from the main form into the subform. Below is the if /then statement i am using: If...
2
by: Etayki | last post by:
Hello, I am trying to create an IF statement that will recognize whether or not a field in the database table is set to some value or if is NULL. Dim myCommand As New...
5
by: akirekab | last post by:
I have a field called PA on a form. The table property is Requred = yes At run time I want to change it based on certain other criteria, to Required = No on Before Update of either the control or...
2
by: mckurban | last post by:
Hi All, I'm not very familiar with Javascript and need help with setting up some javascript code to allow users to create dynamic radio buttons from text field and then to use selected radio value...
5
by: Shortstuff12345 | last post by:
I'm trying to use VBA code to disable a field based on the value of another field in a form. The code I have properly updates the enabled property of the field when it changes; however, it changes...
13
by: curious80237 | last post by:
In Access 2003: A table with four yes/no fields is part of a query used as data source for a report. The yes/no fields show in the datasheet and the report as checkboxes; the default value of the...
3
by: JasonWinchester | last post by:
Hi, all I'm having trouble figuring out how to use an if-then statement to check whether or not a variable is pointing to a look-up column. What I have is a form that contains a combobox and a...
2
by: kent christensen | last post by:
Im trying to create an if then statement in the expression builder. I have a query that has 2 Columns that have currency values in them. I want to set up a new column that basically uses the...
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: 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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.