By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,361 Members | 3,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,361 IT Pros & Developers. It's quick & easy.

Disable objects on text entry

oohrah
P: 10
I have a form that contains 6 textboxes, a combo box and 3 checkboxes. The first textbox is used for a unique id; if the user starts to enter this ID, I need to disable the other 5 texboxes, combo box and 3 checkboxes or enable them if the user removes entered numerics. I have attempted to this under every option under the textbox control that pertains to keypress, keyup, keydown, etc... I have also attempted this under the form options as well. It is probably something very simple and I am simply not in my focused mode. Here is the code for my fired functions
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckEntry()
  2.   If IsNull(txtParcelID.Value) Then
  3.     EnableForm
  4.   Else
  5.     DisableForm
  6.   End If
  7. End Sub
  8.  
  9. Private Sub DisableForm()
  10.   txtOwnerName.Enabled = False
  11.   txtOwnerName.Value = Nothing
  12.   txtPropertyStreetNumber.Enabled = False
  13.   txtPropertyStreetNumber.Value = Nothing
  14.   txtPropertyStreetName.Enabled = False
  15.   txtPropertyStreetName.Value = Nothing
  16.   txtOwnerStreetAddress.Enabled = False
  17.   txtOwnerStreetAddress.Value = Nothing
  18.   txtOwnerCity.Enabled = False
  19.   txtOwnerCity.Value = Nothing
  20.   cboOwnerState.Enabled = False
  21.   cboOwnerState.Value = ""
  22.   txtOwnerZipcode.Enabled = False
  23.   txtOwnerZipcode.Value = Nothing
  24.   chkExempt.Enabled = False
  25.   chkExempt.Value = 0
  26.   chkPaid.Enabled = False
  27.   chkPaid.Value = 0
  28.   chkUnpaid.Enabled = False
  29.   chkUnpaid.Value = 0
  30. End Sub
  31.  
  32. Private Sub EnableForm()
  33.   txtOwnerName.Enabled = True
  34.   txtOwnerName.Value = Nothing
  35.   txtPropertyStreetNumber.Enabled = True
  36.   txtPropertyStreetNumber.Value = Nothing
  37.   txtPropertyStreetName.Enabled = True
  38.   txtPropertyStreetName.Value = Nothing
  39.   txtOwnerStreetAddress.Enabled = True
  40.   txtOwnerStreetAddress.Value = Nothing
  41.   txtOwnerCity.Enabled = True
  42.   txtOwnerCity.Value = Nothing
  43.   cboOwnerState.Enabled = True
  44.   cboOwnerState.Value = ""
  45.   txtOwnerZipcode.Enabled = True
  46.   txtOwnerZipcode.Value = Nothing
  47.   chkExempt.Enabled = True
  48.   chkExempt.Value = 0
  49.   chkPaid.Enabled = True
  50.   chkPaid.Value = 0
  51.   chkUnpaid.Enabled = True
  52.   chkUnpaid.Value = 0
  53. End Sub
  54.  
The function correctly functions when I call the primary sub by other means
Feb 4 '19 #1

✓ answered by oohrah

Knew it was simple. I needed to use .text instead of .value and use the "_change event". So simple yet so far away for a day. Thanks twinnyfo for cleaning up the sub too

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtParcelID_Change()
  2.   Dim vString As String
  3.  
  4.   vString = txtParcelID.Text
  5.  
  6.   If Len(vString) = 0 Then
  7.     EnableForm
  8.   Else
  9.     DisableForm
  10.   End If
  11. End Sub
  12.  

Share this Question
Share on Google+
15 Replies


twinnyfo
Expert Mod 2.5K+
P: 3,284
oohrah,

Welcome to Bytes! Semper Fi!

You cannot check the value of a text box you are currently editing. However, after the update is complete, you can check to see if it is Null.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtParcelID_Change()
  2.     Call EnableControls(Enabled:=IsNull(Me.txtParcelID.Text))
  3. End Sub
  4.  
  5. Private Sub EnableControls(Enabled As Boolean)
  6.     txtOwnerName.Enabled = Enabled
  7.     txtPropertyStreetNumber.Enabled = Enabled
  8.     txtPropertyStreetName.Enabled = Enabled
  9.     txtOwnerStreetAddress.Enabled = Enabled
  10.     txtOwnerCity.Enabled = Enabled
  11.     cboOwnerState.Enabled = Enabled
  12.     txtOwnerZipcode.Enabled = Enabled
  13.     chkExempt.Enabled = Enabled
  14.     chkPaid.Enabled = Enabled
  15.     chkUnpaid.Enabled = Enabled
  16. End Sub
For my example, I removed changing the values of your controls to "Nothing" or "", as it appears you would only use this on new records? Also, we usually set object to Nothing, not values.

Also, it is not exactly clear what it is that youa re trying to do here, although I understand some of the intent.

If someone is entering a value in ParcelID, then the rest of the form should be disabled? If they delete the value in ParcelID the controls are enabled?

One perspective might be to disable all the controls on the form and as the user adds data, check to see if the current field is null, if not, then enable the next control. This allows you to control the user's navigation of the control.

But, again, I'm not exactly sure of the intent here.

Hope this hepps!
Feb 4 '19 #2

oohrah
P: 10
Thanks for the response and OOHRAH back at ya. The purpose of this little program is for my volunteer fire department to keep track of dues paid. I set the print task to for the letters / envelopes / return envelopes to have a unique ID (ParcelID). The issue I am asking about is on the search form. I know I can parse all this out once it is submitted to build my query to search but I was hoping to go one beyond as the people accessing this app are not the most tech suave people around and if I could disable the remaining inputs, maybe they wouldn't waste their time of entering any further. I did it in Access 2000 and the applications I developed in it but seems like a lot has been depreciated in 2013 as to what i was accustomed to. Of course I no longer have access to the mdb's of those apps as they were developed for another company. But I appreciate you refining that part of my code. Guess I can live with disabling everything if they try to access those after entering the ID. My only issue would be with the objects being disabled and they decided the ID is incorrect and delete it out, they wouldn't know to try to click on the other objects to re-enable them. I set values as I wanted to clear any data that may have been entered prior. I set the combo box value to "" as it gave me an error when I use nothing
Feb 4 '19 #3

oohrah
P: 10
Also, I am sure I am not using the most sound programming practices as I was given this Friday and have to have it in place and functioning to some level by Wednesday
Feb 4 '19 #4

twinnyfo
Expert Mod 2.5K+
P: 3,284
So, does the user select a ParcelID and then the form brings up information pertaining to that Parcel?

If you are worried about accidental edits, then, theoretically, when a user opens the form, all they should see is a combo box to select the ParcelID. They select a ParcelID and then the controls with the data pertaining to that ParcelID become visible, but all controls are Locked (If they are Locked, Disabled is immaterial). If they need to edit any of the data to update it, at that point you make available an "Edit" command button, which will unlock those control. Consequently, you can change teh caption on the edit button at that point to be "Save" and then clicking the button again will re-lock the controls.

I'm not sure if that is what you have in mind. If I've missed the target send me a few clicks of windage so I can adjust.
Feb 4 '19 #5

oohrah
P: 10
If the user knows the ID, yes it'll jump straight to a form displaying the info and they will be able to enter payment info. If the user does not know the ID, they can can enter what info the know, even wildcard if need be and it will go to a search results page and they will be able to slect the record from there
Feb 4 '19 #6

oohrah
P: 10
oh, I am not worried about accidental anything as I would never allow a user to directly interact with the Database and there will be a tracking system to will show everything that did / change or add
Feb 4 '19 #7

twinnyfo
Expert Mod 2.5K+
P: 3,284
oohrah
If the user knows the ID, yes it'll jump straight to a form displaying the info and they will be able to enter payment info. If the user does not know the ID, they can can enter what info the know, even wildcard if need be and it will go to a search results page and they will be able to slect the record from there
If you could please explain this just a bit more clearly. You can post an image to this thread using the advanced button on your reply. How does the selection/interaction of the user relate to the initial question of disabling controls. It seems like you have things pretty well locked down. A visual with your description may be a bit more helpfuller.
Feb 4 '19 #8

oohrah
P: 10
Sorry, was called off on other Department issues. Hopefully this may help you to understand a bit more



What I was hoping for was once anything was entered, be it numeric or alphanumeric, that other fields besided the ID field would be disabled like:



and, likewise, if the data entered for ID were removed it would reenable and clear old data back to original form state

To further explain about what you asked about on the user knowing the ID:

The user will have 2 possible outcomes;

If the User knows the ID(First object in the Form labeled as ID). It should disable the other objects as denoted in the second image provided. Or if the user must enter owner or property details in the appropriate fields or combo box or even the check boxes.

Upon the user entering the data they know and pressing the "Enter" Button on their keyboard, as key preview is enabled on the form and the command on the form labeled "Search Parcels", which is set via the property menu as the default, or by moving their mouse over the previously mentioned command and click with the mouse button, will perform a search in code in the background to determine the number of matching records from the user provided data.

If this search, performed in code and in the background unseen by the user, only locates one matched record, it will immediate display a yet to be designed form displaying only the matching records data. If it finds multiple matches it will display a form that will display a form, yet to be designed also, showing all matching records in a datagridview object where they can select the record they wish to view and display the, yet to be designed form, mentioned first and displaying the information for the record they selected in the second, yet to be designed form, mentioned.

I do not have a problem explaining the logic for elements that were not part of the original question for a more complete understanding. Hope this helps you understand
Feb 5 '19 #9

twinnyfo
Expert Mod 2.5K+
P: 3,284
So......

First, I would say that, unless the code I provided in my first response does not work, then, that is the "answer" to this thread.

However, I do believe we are talking about things that go way beyond the scope of the original thread.

Now knowing that what you have been describing is a "Search" form and not a "Data Entry" form is very helpful.

This more appropriately belongs in a separate thread, such as "Using a Search Form to Find Records", concerning which I do have some recommendations. I would be glad to move these few posts to a new thread, if you so desire.

As a hint, I think you may be getting too wrapped around the axle with prohibiting some controls based upon the entry into one such control. There are better ways to manage that--which we can discuss in a new thread....
Feb 5 '19 #10

oohrah
P: 10
Knew it was simple. I needed to use .text instead of .value and use the "_change event". So simple yet so far away for a day. Thanks twinnyfo for cleaning up the sub too

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtParcelID_Change()
  2.   Dim vString As String
  3.  
  4.   vString = txtParcelID.Text
  5.  
  6.   If Len(vString) = 0 Then
  7.     EnableForm
  8.   Else
  9.     DisableForm
  10.   End If
  11. End Sub
  12.  
Feb 5 '19 #11

oohrah
P: 10
Well, as my title and question state, "Disable objects on text entry",correct? You asked for further details
Feb 5 '19 #12

twinnyfo
Expert Mod 2.5K+
P: 3,284
Yes - I did.

However, it appears to me that you are wrestling with a different issue. Although you can achieve your initial, limited objective, what I am trying to encourage you to do is look at the issue more holistically:

Here are your assumptions:
  • The user knows the ParcelID - OR
  • The user does not know the ParcelID

What you are trying to do is build into your form the capability for both types of users to engage with the data, yes? Now, there is no one right way to skin this or any other cat, but rather than complexify things with giving the form a limited sense of artificial intelligence, let the user use their own intelligence to determine what happens.

For example, your form would default to allowing the user to enter the ParcelID. Nothing else is displayed, because your initial assumption will be that the user knows the ParcelID they want to look up (granted, it may be an incorrect assumption, but this is just where you are beginning).

Aww snap! I forgot my ParcelID! But your form has a button the user can click which now disables the ParcelID text box and displays all the other text boxes. Now you don't need the form to think for itself. Again, my suggestion is not "the right way", but it is a different way for you to engage with what you are trying to do, keeping it as simple as possible.

Additionally, the more search text fields you include in your query, the more complex you make your search algorithm. Plus, you also open the door (based upon what I see) for folks returning false results or no results at all. For example, I live near Virginia Beach, Virginia. If you ask people to put in their city, how are they going to put it in? I've seen the following for this one city:
  • Virginia Beach
  • Va Beach
  • Va. Beach
  • Virginia Bch
  • VB
  • V.B.
  • VA Bch
  • Va. Bch
  • etc.

The database will see all these values as distinct cities, and trying to build in a fuzzy search algorithm for a database like this seems, again, to over-complexify things.

I am not trying to poke you in the eye--that is never my intent. However, I would ask that you think through things very carefully for this form. I don't know how many records and users you are dealing with, but if you are looking for simplicity (for the user) there may be better (or at least alternate) ways of approaching this search form.

This is one of the reasons I ask for additional information. Not to point out how you are wrong, but to see if the direction you are going may lead to additional challenges. That's part of what we try to do on Bytes. We want you to be successful, not just solve a particular problem and be done with it.

You seem like you have a good grasp of things, so I won't belabor the point. Just offering some food for thought.
Feb 5 '19 #13

oohrah
P: 10
Reading too much in to it. I just needed to disable 3 checkboxes, 5 textboxes and a dropdown box based on whether a user had the ID(specfic data) or needed to do further data entry. I've have the search covered and dealt with and actually have the application up and running now. Thanks for cleaning that code up, I will continue to further refine the code as time goes one but the initial request of the very first post has been answered:
"I have a form that contains 6 textboxes, a combo box and 3 checkboxes. The first textbox is used for a unique id; if the user starts to enter this ID, I need to disable the other 5 texboxes, combo box and 3 checkboxes or enable them if the user removes entered numerics. I have attempted to this under every option under the textbox control that pertains to keypress, keyup, keydown, etc... I have also attempted this under the form options as well. It is probably something very simple and I am simply not in my focused mode. Here is the code for my fired functions "
Feb 6 '19 #14

oohrah
P: 10
I don't wanna get into an argument. My original post has the title of "Disable objects on text entry". I have now had 14 people look at it and the agree. I knew hows to build my query meaning I did not need help with that. I asked how to disable other textboxes when a user starts entering data. That was I was asking about. So explain to me how elaborating on your request for more details. How would you knowing it was a search screen better answer what I was asking? Asking because I figured it out without any consideration to being a form for a user to search from?
Feb 7 '19 #15

twinnyfo
Expert Mod 2.5K+
P: 3,284
My request for additional information has to do with the "Why?" My stance is that you might approach a seach form differently than a data entry form. Nothing more, nohting less. Again, I try to suggest alternate ways to approach a problem.

You are correct--the solution is the solution. You will notice that after post #14, you made your stance clear and there was no need for a response (meaning, I thought that simply closed out the thread).

If you skim enough of the threads here, you will also find that there are some questions to which I will not provide an answer, because to do so would lead the OP down an incorrect path of DB design. While I was less concerned about that with you, it is often better to "understand the whole problem"--not just give an answer blindly.

You are certainly free to accept or decline any assistance and recommendations you receive here.
Feb 7 '19 #16

Post your reply

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