Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form design 2 2

Status
Not open for further replies.

carrs09

IS-IT--Management
Dec 29, 2009
7
GB
I am designing a data entry form. The form will have four fields.
However I am trying it to design it in such a way that one of the fields only pops up on the form when certain information has been entered in field three.

For instance Field 3 requires an input of 'length of time at present address'. If the value entered in this field is less than three years, the form should then immediately display Field 4 which requires 'the previous address'
 

Start with the visible property of your 4th text box set to FALSE.
In the On Current event of the form...
Code:
If Me.[i]NameOf3rdTextBox[/i] < 3 Then
    [i]NameOf4thTextBox[/i].Visible = True
End If

Randy
 
The code should be in the After Update of NameOf3rdTextBox as well as the On Current. You can add this function in the form's module and then set the On Current and after update events of 3rd to:
[tt]
=ShowHide4th()
[/tt]
Code:
Public Function ShowHide4th()
    NameOf4thTextBox.Visible = Me.NameOf3rdTextBox < 3
End Function

Duane
Hook'D on Access
MS Access MVP
 
Hi
Thanks very much for your response. Could you explain further, the part about "adding the function in the form's module" How do I actually do this bit?
Thanks once again
 
You select View->Code from the menu to get to the form's code. Then copy and paste the function into the code window. It looks a little like notepad. Then exit the code window and save it.

Duane
Hook'D on Access
MS Access MVP
 
Hi
A great many thanks to randy700 and dhookom for the responses. I have totay tried both methods you gave but am encountering a few problems and need a bit more help. The codes are coming up with errors.

1) What do I use as the 'name of the text box'? - in my case the text box has a combo. Do I need to use any brackets?

2) Regarding 'adding the function in the form's module', I have opennd the form in design view, gone on to VIEW but I cannot see the CODE option there. This is Access 2007
 
carrs09

1) To find the name of the text box (or combo box), click it in design view and look at the properties tab. Look at the "All" tab of the items and there is an item "Name"
This is what needs to go into the name of the textbox.

2) To open the module, with the form in Design view, hold down the Alt key and press F11.
This will open the VBA editor window.

John
 
jrbarnett
Thank you very much for your response. I have now tried both methods but thereis still no joy.
With the first method (the one from randy700, no error messages come up but I am not getting the result. i.e. when field 3 has been changed I am not getting field 4 to pop up.

With the second method, the one from dhookom an error message is coming up. It says "The expression On Current you entered as the event property produced the following error: Invalid Use of Null

I dont know whether this is significant but the field criteria is now slightly different. I am trying to get field 4 to pop up when field 3 contains the value "PAID UP SHARES". Will there be any major difference to the code apart from swapping the "<" with an "="

Is there any other method I can use?
 
What is YOUR actual code raising the error ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi
The code I have used is the one suggested by dhookom in an earlier post. It goes something like:

CODE
Public Function ShowHide4th()
NameOf4thTextBox.Visible = Me.NameOf3rdTextBox < 3
End Function

This code would have been created as "ShowHide4th" in the forms module. I then set the On Current and After Update events of the form and 3rd text box respectively by using the text "=ShowHide4th()"

Thanks
 
Did you not change my made-up names of controls with your actual names? Replace the red text with your actual names.

Code:
Public Function ShowHide4th()
    Me.[red]NameOf4thTextBox[/red].Visible = Me.[red]NameOf3rdTextBox[/red] < 3
End Function

Duane
Hook'D on Access
MS Access MVP
 
error: Invalid Use of Null
Replace this:
Me.NameOf4thTextBox.Visible = Me.NameOf3rdTextBox < 3
with this:
Me.NameOf4thTextBox.Visible = Nz(Me.NameOf3rdTextBox < 3, False)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
dhookom
Hi
Yes I DID change the names - i have put my actual names!
The other thing is my criteria is slightly different to the example
I want the fourth field to pop up when the value in the 3rd field is PAID UP SHARES.
If you check my earlier post, I have given the full text of the error message that is coming up
Thanks
 
So, you wanted this ?
Me!NameOf4thTextBox.Visible = (Me!NameOf3rdTextBox & "" = "PAID UP SHARES")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top