+ Reply to Thread
Results 1 to 10 of 10

Can I automatically hide/show text fields in a form?

  1. #1
    Registered User
    Join Date
    06-04-2015
    Location
    savona,italy
    MS-Off Ver
    2007
    Posts
    5

    Can I automatically hide/show text fields in a form?

    Sorry for the question,
    perhaps it will have an easy solution, but I have not found it.
    I would like to automatically display the fields of a form, and populate them with data from a dynamic table.
    The code I wrote is not working.
    Do I have to declare, the full name of the text box?
    How can I declare the name of the field dynamically?


    here is my code........

    'begin script *******************************************
    Load MyForm
    With MyForm

    For t = 1 To 40
    field = "Text" & t 'Text1 - Text2 - Text3 ....... are the names of the text box in MyForm
    .field.Visible = False

    If MyArray(t) > "" Then
    .field = MyArray(t)
    .field.Visible = True

    End If
    Next t

    .Show

    End With

    'end script ********************************************************************

    thanks a lot, from acamarsv

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Can I automatically hide/show text fields in a form?

    Please Login or Register  to view this content.
    kind regards
    Leo

  3. #3
    Registered User
    Join Date
    06-04-2015
    Location
    savona,italy
    MS-Off Ver
    2007
    Posts
    5

    Re: Can I automatically hide/show text fields in a form?

    Thanks, for your answer, but this script, needs a button . I must show/hide, dynamically, the fields. Without push any button.
    I have an array in which fields are on/off , depending on varying parameters.
    At every elaboration the fields change their state on/off

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Can I automatically hide/show text fields in a form?

    so you place the code where needed, for exemple in the event exit of TextBox

    Please Login or Register  to view this content.
    kind regards Leo

  5. #5
    Registered User
    Join Date
    06-04-2015
    Location
    savona,italy
    MS-Off Ver
    2007
    Posts
    5

    Re: Can I automatically hide/show text fields in a form?

    your code
    If me.textbox4.value > 100 then me.textbox1.visible = false
    if me.textbox4.value < 101 then me.textbox1.visible = true

    my problem is to give a name dynamically to the text box
    so "me.textbox4.value" must become "me.myvariant.value" where myvariant is a variant containing the name of the text box, in this case "textbox4"

    if possible my new code :

    text1 = "textBox4"
    text2 = "textBox1"
    Variant1 = true
    Variant2 = false

    if Variant1 then me.Text1.visible = false
    if Variant2 then me.Text2.visible = true

    thanks again

  6. #6
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Can I automatically hide/show text fields in a form?

    time for a excel file with desired result


    Kind regards
    Leo

  7. #7
    Registered User
    Join Date
    06-04-2015
    Location
    savona,italy
    MS-Off Ver
    2007
    Posts
    5

    Re: Can I automatically hide/show text fields in a form?

    I'm also looking it, for long time, but no result.
    May be that I am not a good patch finder

    Thanks a lot
    Marcello

  8. #8
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Can I automatically hide/show text fields in a form?

    you dont have to look at it you have to place it

    exemple with the real situation before and after (manuel)

    then someone here can make it automatic


    kind regards
    Leo

  9. #9
    Forum Contributor
    Join Date
    04-20-2015
    Location
    Switzerland
    MS-Off Ver
    2010
    Posts
    312

    Re: Can I automatically hide/show text fields in a form?

    Just loop through all textboxes and check theyr name

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-04-2015
    Location
    savona,italy
    MS-Off Ver
    2007
    Posts
    5

    Thumbs up Re: Can I automatically hide/show text fields in a form?

    solution foud !!!!!!

    Option Explicit

    Dim MyArray(40)

    Sub TestTT()
    Dim t As Integer, field As Control

    For t = 1 To 40
    MyArray(t) = Round(Sqr(t) * t * Rnd(t), 2)
    Next t

    Load MyForm

    With MyForm
    For t = 1 To 40
    Set field= .Controls("text" & t) '<<<<< this is the solution to my problems
    field.Visible = True ' all textbox - hidden
    If MyArray(t) > 5 Then '
    field.Visible = true ' show the textbox
    field.Value = MyArray(t) ' populate the text box
    End If
    Next t
    .Show

    End With

    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Using form checkbox responses to determine which worksheets to show/hide
    By yukinosei in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2014, 12:34 PM
  2. Select which summed value fields to show or hide on PivotChart
    By PixlPgsis in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-21-2013, 03:46 PM
  3. How to show/hide/unload form when form name is a string variable?
    By achmidt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 06:21 PM
  4. Automatically Show/Hide Gridlines And Headlines
    By Eric Excels in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-30-2011, 10:29 PM
  5. Automatically complete fields on a form
    By piercer in forum Access Tables & Databases
    Replies: 1
    Last Post: 08-17-2010, 05:40 PM
  6. How to hide '0' shown in empty fields (Access form)
    By WillysK5 in forum Access Programming / VBA / Macros
    Replies: 5
    Last Post: 05-22-2009, 10:16 AM
  7. [SOLVED] Show/Hide Causes Error on Form Close
    By Trip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2005, 07:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1