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

Home Posts Topics Members FAQ

Lock TextBox if another TextBox's value is "" or Null

7 New Member
I'm having some trouble with a particular form. I would like to lock a textbox until 7 other textboxes have a value in them. The other 7 textboxes are a mixture of text fields, double numers, currency, and dates. The textbox that I would like to keep locked (until conditions are met) is a date field. This is what I have so far. Keep in mind that this particular vba code only looks at one of the seven fields.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ReviewComplete_Exit(Cancel As Integer)
  2. If Not IsNull(ReviewComplete.Value) And Borrower.Value = "" Then
  3.     MsgBox "no borrower", vbOKOnly
  4.     Else
  5. End If
  6. End Sub
  7.  
This code does not seem to be working as it does not produce a message box when I tab out or click out of the ReviewComplete textbox. Any help is very much appreciated. Thank you!

Ryan E.
Jan 9 '08 #1
18 10375
ADezii
8,834 Recognized Expert Expert
I'm having some trouble with a particular form. I would like to lock a textbox until 7 other textboxes have a value in them. The other 7 textboxes are a mixture of text fields, double numers, currency, and dates. The textbox that I would like to keep locked (until conditions are met) is a date field. This is what I have so far. Keep in mind that this particular vba code only looks at one of the seven fields.

Private Sub ReviewComplete_Exit(Cancel As Integer)
If Not IsNull(ReviewComplete.Value) And Borrower.Value = "" Then
MsgBox "no borrower", vbOKOnly
Else
End If
End Sub

This code does not seem to be working as it does not produce a message box when I tab out or click out of the ReviewComplete textbox. Any help is very much appreciated. Thank you!

Ryan E.
  1. Set the Locked Property of the Text Box to be Locked/Unlocked to Yes. For demo purposes I'll name it txtLocked.
  2. Create a Private Sub-Routione in your Form and name it SetStatusOfTextBox.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub SetStatusOfTextBox()
    2. If IsNull(Me![txtBox1]) Or IsNull(Me![txtBox2]) Or IsNull(Me![txtBox3]) Or IsNull(Me![txtBox4]) Or IsNull(Me![txtBox5]) Or IsNull(Me![txtBox6]) Or IsNull(Me![txtBox7]) Then
    3.   Me![txtLocked].Locked = True
    4. Else
    5.   Me![txtLocked].Locked = False
    6. End If
    7. End Sub
  3. In the AfterUpdate() Event of each of the 7 Text Boxes, place the following single line of code:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub txtBox2_AfterUpdate()
    2.   Call SetStatusOfTextBox
    3. End Sub
  4. Replace the Text Box Names and the Sub-Routine name if you like.
  5. Any questions, feel free to ask.
  6. There is an easier Method but I'm assuming that there are additional Text Boxes on the Form beside the 7 that need to contain values and the 1 which will be Locked/Unlocked.
Jan 10 '08 #2
ryanvb83
7 New Member
Perfect!!!! Thank you sooo much. I'll be able to use the same logic to solve another issue I was having!
Jan 10 '08 #3
jambonjamasb
41 New Member
Would that code also work to hide a textbox rather than lock it? I have one text box that when another is null I want it to remain hidden.
Jan 10 '08 #4
ryanvb83
7 New Member
I pretty sure it would. Just replace .locked with .hidden
Jan 10 '08 #5
Minion
108 Recognized Expert New Member
I pretty sure it would. Just replace .locked with .hidden
Actually, I believe the property you are looking for is visible not hidden. The code to hide an element would look like:
Expand|Select|Wrap|Line Numbers
  1. yourTextBox.visible = False
  2.  
That should work to hide the element using the previously posted code.

- Minion -
Jan 10 '08 #6
ADezii
8,834 Recognized Expert Expert
Perfect!!!! Thank you sooo much. I'll be able to use the same logic to solve another issue I was having!
You are quite welcome.
Jan 10 '08 #7
ADezii
8,834 Recognized Expert Expert
Would that code also work to hide a textbox rather than lock it? I have one text box that when another is null I want it to remain hidden.
Would that code also work to hide a textbox rather than lock it?
Yes, just replace .Locked with .Visible.
Jan 10 '08 #8
jambonjamasb
41 New Member
Do I make the change in the actual table or on my report.

The field change_withdrawn has a tick box and when this is ticked I want the reason_for withdrawal box to appear which has a drop down selection?

I have looked at the fields properties and there is a yes no choice do i need to select this?

Thanks for your help in advance.
Jan 10 '08 #9
jambonjamasb
41 New Member
Do I make the change in the actual table or on my report.

The field change_withdrawn has a tick box and when this is ticked I want the reason_for withdrawal box to appear which has a drop down selection?

I have looked at the fields properties and there is a yes no choice do i need to select this?

Thanks for your help in advance.
Sorry just read the bit which stated do a private sub routine on the form.
Jan 10 '08 #10
jambonjamasb
41 New Member
Sorry just read the bit which stated do a private sub routine on the form.
On form POL_Actions_Enter I clicked on properties of combo box Reason_For_Withdrawal

I then selected Events and before updates line. in there I typed the following.


Private Sub POL_Actions_Enter()
If IsNull(Me![Change_Withdrawn])
Me![Reason_for_Withdrawal].Visible = False
Else
Me![Reason_for_Withdrawal].Visible = True
End If
End Sub

I assumed if change withdrawn is null then reason for withdrawal isnt visible?

For some reason the code wont step forward, but I am not knowledgable enough to understand why. Also not sure if this is the cause, but my whole sub form has vanished from my main form. LOL what do they say, "If it ain't broke, fiddle with it!"

Thanks in advance.
Jan 10 '08 #11
jambonjamasb
41 New Member
Right.

I have spotted that I missed a "then" and had a couple of brackets that weren't needed. So my code now reads.


Private Sub POL_Actions_Enter()
If IsNull(Me!Change_Withdrawn) Then
Me!Reason_for_Withdrawal.Visible = False
Else
Me!Reason_for_Withdrawal.Visible = True
End If
End Sub

End Sub

While this looks right to me it still doesnt work. Am I right that this is an event procedure in properties? Also since I entered this code my subform has vanished. POL_Actions is the name of the form. This is the first database I have properly built so apologies for my ineptness.
Jan 11 '08 #12
ADezii
8,834 Recognized Expert Expert
Right.

I have spotted that I missed a "then" and had a couple of brackets that weren't needed. So my code now reads.


Private Sub POL_Actions_Enter()
If IsNull(Me!Change_Withdrawn) Then
Me!Reason_for_Withdrawal.Visible = False
Else
Me!Reason_for_Withdrawal.Visible = True
End If
End Sub

End Sub

While this looks right to me it still doesnt work. Am I right that this is an event procedure in properties? Also since I entered this code my subform has vanished. POL_Actions is the name of the form. This is the first database I have properly built so apologies for my ineptness.
Place your code in the AfterUpdate() Event of Change_Withdrawn.
Jan 11 '08 #13
Minion
108 Recognized Expert New Member
Just a little tip for posting on this board. When you're posting any type of code it really helps to put in the brackets ([ code=vb ] <<code>> [ /code ]) (without spaces inside brackets) this will format the code. If you have sql or other language just change the vb to the proper format.

For instance you posted..

Private Sub POL_Actions_Enter()
If IsNull(Me!Change_Withdrawn) Then
Me!Reason_for_Withdrawal.Visible = False
Else
Me!Reason_for_Withdrawal.Visible = True
End If
End Sub

If you place this within the code tags as described it looks like.
Expand|Select|Wrap|Line Numbers
  1. Private Sub POL_Actions_Enter()
  2. If IsNull(Me!Change_Withdrawn) Then
  3.   Me!Reason_for_Withdrawal.Visible = False
  4. Else
  5.   Me!Reason_for_Withdrawal.Visible = True
  6. End If
  7. End Sub
  8.  
Just a little hint to make longer bits of code easier to read.

Thanks.

- Minion -
Right.

I have spotted that I missed a "then" and had a couple of brackets that weren't needed. So my code now reads.


Private Sub POL_Actions_Enter()
If IsNull(Me!Change_Withdrawn) Then
Me!Reason_for_Withdrawal.Visible = False
Else
Me!Reason_for_Withdrawal.Visible = True
End If
End Sub

End Sub

While this looks right to me it still doesnt work. Am I right that this is an event procedure in properties? Also since I entered this code my subform has vanished. POL_Actions is the name of the form. This is the first database I have properly built so apologies for my ineptness.
Jan 11 '08 #14
Minion
108 Recognized Expert New Member
Just thought of something when I was reading over the thread again. If you're looking to use the check to activate another control you may wish to use .Enabled instead. This will still show the control on the form so the user will know there is one, but will gray it out until the first control code is activated. So your code would look like.

Expand|Select|Wrap|Line Numbers
  1. Private Sub POL_Actions_After_Update()
  2. If IsNull(Me!Change_Withdrawn) Then
  3.   Me!Reason_for_Withdrawal.Enabled = False
  4. Else
  5.   Me!Reason_for_Withdrawal.Enabled = True
  6. End If
  7. End Sub
  8.  
Jan 11 '08 #15
Minion
108 Recognized Expert New Member
Just thought of something when I was reading over the thread again. If you're looking to use the check to activate another control you may wish to use .Enabled instead. This will still show the control on the form so the user will know there is one, but will gray it out until the first control code is activated. So your code would look like.

Expand|Select|Wrap|Line Numbers
  1. Private Sub POL_Actions_After_Update()
  2. If IsNull(Me!Change_Withdrawn) Then
  3.   Me!Reason_for_Withdrawal.Enabled = False
  4. Else
  5.   Me!Reason_for_Withdrawal.Enabled = True
  6. End If
  7. End Sub
  8.  
Just a thought.

- Minion -
Jan 11 '08 #16
jambonjamasb
41 New Member
Just thought of something ...........

Expand|Select|Wrap|Line Numbers
  1. Private Sub POL_Actions_After_Update()
  2. If IsNull(Me!Change_Withdrawn) Then
  3.   Me!Reason_for_Withdrawal.Enabled = False
  4. Else
  5.   Me!Reason_for_Withdrawal.Enabled = True
  6. End If
  7. End Sub
  8.  
Just a thought.

- Minion -
Hi Min,

I highlighted Change_Withdrawn
Selected after event and entered into the code builder
Private Sub Change_Withdrawn_AfterUpdate()
If IsNull(Me!Change_Withdrawn) Then
Me!Reason_for_Withdrawal.Enabled = False
Else
Me!Reason_for_Withdrawal.Enabled = True
End If
End Sub

I also tried to replace enabled with visable, both returned error code 438. I read through the help in access and didn't really understand it. Is this due to how I created the private sub or how I named it?
Jan 14 '08 #17
jambonjamasb
41 New Member
Thanks for all your help with this sorry to be such a pain.
Jan 14 '08 #18
jambonjamasb
41 New Member
I have also been on the microsoft website and again it was talking about binary updates as you are aware I only have a basic knowledge of access, but thanks to you guys it is growing.
Jan 14 '08 #19

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

Similar topics

27
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
3
by: Paul T. Rong | last post by:
Do "" and Null both mean nothing?¡¡ If I don't type anything in text box, the its value is Null£¿¡¡Or it is ¡°¡±£¿ I don¡¯ think they are the same, but I don¡¯t know their difference. Thanks.
43
by: markryde | last post by:
Hello, I saw in some open source projects a use of "!!" in "C" code; for example: in some header file #define event_pending(v) \ (!!(v)->vcpu_info->evtchn_upcall_pending & \...
3
by: MLH | last post by:
On frmVehicleEntryForm... I wanted to change the DefaultValue property of one of my textbox controls on a form from within code. I wanted the setting to be no setting - as if nothing had ever...
2
by: uninvitedm | last post by:
I have a table which I'm extracting data from with a SELECT statement(and outputing as a text file), there's some changes I want to make to the extracted data before it is output (not the actual data...
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
21
by: Sami | last post by:
string = "" or string = string.Empty? should is the proper way? Sami
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.