473,473 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Backwards code works Forwards? Why?

135 New Member
I quickly put this code together to test if it would disable some of my functions OnChange when my text box (purchase order number) is empty...and if it would enable those functions when I added data to my field. The funny thing is that if you read the code it actually runs in reverse! When my field is null it is suppose to disable...instead it enables...Why? So I put my code in to do the opposite of what I want and it works!?!?! I don't mind having my code in logical reverse as long as I get the results I'm looking for...but...I don't get it....???? ;-)


Forwards: (works in reverse and enables features when Null)
Expand|Select|Wrap|Line Numbers
  1. Private Sub PurchaseOrderNumber_Change()
  2. If IsNull(Me.PurchaseOrderNumber) Then
  3. Me.Check107.Enabled = False
  4. Me.Check111.Enabled = False
  5. Me.Text77.Enabled = False
  6. Me.Label119.Visible = True
  7. Else
  8. Me.Check107.Enabled = True
  9. Me.Check111.Enabled = True
  10. Me.Text77.Enabled = True
  11. Me.Label119.Visible = False
  12. End If
  13.  
  14. End Sub
Backwards: (disables features when null)
Expand|Select|Wrap|Line Numbers
  1. Private Sub PurchaseOrderNumber_Change()
  2. If IsNull(Me.PurchaseOrderNumber) Then
  3. Me.Check107.Enabled = True
  4. Me.Check111.Enabled = True
  5. Me.Text77.Enabled = True
  6. Me.Label119.Visible = False
  7. Else
  8. Me.Check107.Enabled = False
  9. Me.Check111.Enabled = False
  10. Me.Text77.Enabled = False
  11. Me.Label119.Visible = True
  12. End If
  13.  
  14. End Sub
May 17 '09 #1
18 1998
FishVal
2,653 Recognized Expert Specialist
Hello.

I suggest you to perform a little experiment - add two controls on the form and in PurchaseOrderNumber_Change event handler assign PurchaseOrderNumber.Value property and PurchaseOrderNumber.Text property values to them.

Regards,
Fish.
May 17 '09 #2
MyWaterloo
135 New Member
@FishVal
Ooook that was interesting.....So....what is that showing me. A little bizarre, but I have no idea what these results tell me... =-)




"So, where did you learn Access?"

"Learn Access? Who? Me?"
May 17 '09 #3
FishVal
2,653 Recognized Expert Specialist
@MyWaterloo
I guess it explains why your code behaves in a way you don't expect.

Kind regards,
Fish.
May 17 '09 #4
MyWaterloo
135 New Member
@FishVal
I don't understand how it explains what my code is doing. Why do the two controls behave the way they do? Why does the code work, but in a way that appears to be in reverse? I just don't see how the two controls reveal why the code behaves the way it does.






"I can design a fantastic looking form for you. With buttons and menus and everything."
"What do they do?"
"What?"
"The buttons and menus."
"I have no idea, but they sure look good."
May 17 '09 #5
MyWaterloo
135 New Member
OK. I see that (for whatever reason I don't know) this current process of mine will not work. I guess I'm at a dead end. I was hoping to disable certain features if one of my fields was not filled in i.e. null. =(
May 17 '09 #6
FishVal
2,653 Recognized Expert Specialist
@MyWaterloo
I think it is quite straightforward.

PurchaseOrderNumber.Value property is a default property you implicitly invoke when checking condition for enabling/disabling.
This little experiement shows you what this property returns when PurchaseOrderNumber_Change event fires thus making clear why the code behaves the way it behaves. At the same time value returned by PurchaseOrderNumber.Text property is , I guess, a more relevant criteria for making decision whether the controls should be enabled or disabled.

Does it make more sense now?
May 17 '09 #7
MyWaterloo
135 New Member
Yes, it kind of makes sense to me. I guess what it really means is that I need to come up with some other way to disable my print buttons if my P.O. number field is null. Any ideas? (Thanks for the lesson.)
May 17 '09 #8
mshmyob
904 Recognized Expert Contributor
subscribing just to watch the fun.

cheers,
May 17 '09 #9
NeoPa
32,556 Recognized Expert Moderator MVP
Did the values ever get posted?

Fish & the OP seem to be discussing something they can both see but I for one, don't see any values posted (Emperor's clothes! I was never one to try to hide my ignorance so I will always ask the questions).
May 18 '09 #10
mshmyob
904 Recognized Expert Contributor
I think what you were told was to use the .text property instead of the .value property.

You could also the the NZ function and then check the value of the variable to see if NULL and do the appropriate commands.

cheers,

@MyWaterloo
May 19 '09 #11
mshmyob
904 Recognized Expert Contributor
Just to reword Fishval's response....

There is a slight difference between the .Value and .Text property. It is subtle but an important difference.

The .Value property refers to the saved value of the textbox while the .text property refers to the current contents of the textbox. Therefore, until you lose focus you should use the .text property to determine the contents of the textbox.

Does this help explain why your code works in reverse?

cheers,
May 19 '09 #12
MyWaterloo
135 New Member
@mshmyob
Yes, that helped bring light to the subject. So when I lose focus of the textbox I have to use the .value property?
May 20 '09 #13
mshmyob
904 Recognized Expert Contributor
I am glad it helps you a bit but you do not need to use the .value property you can use the .text property all the time.

cheers,

@MyWaterloo
May 20 '09 #14
MyWaterloo
135 New Member
@mshmyob
Ok. I will give it a go.
May 20 '09 #15
MyWaterloo
135 New Member
OK. So I still don't understand this. =-( I can't figure out how to code this so if my Purchase Order field is Null my print features are disabled, and if it has a number my print features are enabled. ????? Help?????
May 21 '09 #16
mshmyob
904 Recognized Expert Contributor
Maybe you are getting confused with NULL and zero length strings?

Anyways try this in the AfterUpdate event

Expand|Select|Wrap|Line Numbers
  1. If Len(Me.Text0.Text) = 0 Then
  2.     'your code if no value is present
  3. Else
  4.     'your code if data is present
  5. End If
  6.  
You would also need to check your LostFocus event in case there is no data in the text control when first loaded and the user just tabs off and tries to print.

I would really put the code in the OnClick event of your button for printing.

cheers,

@MyWaterloo
May 21 '09 #17
FishVal
2,653 Recognized Expert Specialist
  • If you want print features state to reflect [Purchase Order] textbox content immediately, then you should handle Change event which fires whenever user changes it. The code in the event handler should check whether [Purchase Order].Text property returns empty string ("") - note, Text property returns String type value, it couldn't be Null. If it is so, then code disables print features, otherwise - enables.
  • If you want print features state to reflect [Purchase Order] textbox content as soon as user confirmed input by moving focus to another control, then you should handle AfterUpdate event. The code in the event handler should check whether [Purchase Order].Value property returns Null. See the difference? Value property returns Variant type value, moreover it is generally not the same that Text property returns but more like a result of input interpretation in context of what the textbox control expects to get as input.
May 21 '09 #18
MyWaterloo
135 New Member
@mshmyob
Thanks. Yes, I was getting confused with Null... I actually have some code similar on my print button. I wanted this code to disable my print buttons and then display a label that is draped over the print buttons telling the user "P.O. number required to enable print features." I don't want to require a P.O. number on the form to enable saving of the record...just encourage it. Some P.O.'s don't have numbers as they are being filled out and then the user comes back later to add data. The number is from an outside source and is given when it si time to print/save. So the number must be present to print/save as a file. I just wnated it clear right from the start that a P.O. is required to do any kind of output. Thnaks, I'll try this and let you know how it goes.
May 21 '09 #19

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

Similar topics

8
by: Chris | last post by:
Can anybody help. I need to read a txt file backwords line by line. Can anybody help me do this. Thanks Chris
7
by: Jay | last post by:
I have a very large text file (being read by a CGI script on a web server), and I get memory errors when I try to read the whole file into a list of strings. The problem is, I want to read the file...
15
by: SK | last post by:
Hey folks, I am searching for a string (say "ABC") backwards in a file. First I seek to the end. Then I try to make a check like - do { file.clear (); file.get(c); file.seekg(-2,...
11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
3
by: Adrian | last post by:
> Hi > > I'm lost! so please help me... > > I have the following code > > I want to simply retrieve all the record that matches the SQL statement, I > want to know how many records matched and...
1
by: Orestis Markou | last post by:
Hello, I'm the developer of PySmell ( http://github.com/orestis/pysmell ), a static analysis/intellisense provider for Python. I am targeting Python 2.4 code so I'm using the compiler package. ...
0
by: Terry Reedy | last post by:
Orestis Markou wrote: My impression is that the 2.6 ast package is quite different from the 2.4 compiler package, but I have not looked at it (in its 3.0 version) yet. If the 2.4 code you are...
0
by: chromis | last post by:
Hi, I'm creating virtual tour of a house, the part I am working on at the moment involves a 360 spin view of the house (a series of 36 flat frames). Each corner of the house has a hotspot so that...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.