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) - Private Sub PurchaseOrderNumber_Change()
-
If IsNull(Me.PurchaseOrderNumber) Then
-
Me.Check107.Enabled = False
-
Me.Check111.Enabled = False
-
Me.Text77.Enabled = False
-
Me.Label119.Visible = True
-
Else
-
Me.Check107.Enabled = True
-
Me.Check111.Enabled = True
-
Me.Text77.Enabled = True
-
Me.Label119.Visible = False
-
End If
-
-
End Sub
Backwards: (disables features when null) - Private Sub PurchaseOrderNumber_Change()
-
If IsNull(Me.PurchaseOrderNumber) Then
-
Me.Check107.Enabled = True
-
Me.Check111.Enabled = True
-
Me.Text77.Enabled = True
-
Me.Label119.Visible = False
-
Else
-
Me.Check107.Enabled = False
-
Me.Check111.Enabled = False
-
Me.Text77.Enabled = False
-
Me.Label119.Visible = True
-
End If
-
-
End Sub
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.
@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?"
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.
@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."
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. =(
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?
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.)
mshmyob 904
Recognized Expert Contributor
subscribing just to watch the fun.
cheers,
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).
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 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,
@mshmyob
Yes, that helped bring light to the subject. So when I lose focus of the textbox I have to use the .value property?
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
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?????
mshmyob 904
Recognized Expert Contributor
Maybe you are getting confused with NULL and zero length strings?
Anyways try this in the AfterUpdate event -
If Len(Me.Text0.Text) = 0 Then
-
'your code if no value is present
-
Else
-
'your code if data is present
-
End If
-
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 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.
@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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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,...
|
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...
|
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?
| |
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...
|
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.
...
|
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...
|
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...
|
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...
|
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,...
| |
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: 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...
|
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...
|
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...
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |