Results 1 to 6 of 6
  1. #1
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32

    Changing the input state of Control element between a choice list or type text input


    Hello, I am currently trying to build a form (which is actually a subform) with some inputs that can be chosen from under certain circumstances.

    There is a certain control element that has two inputs and that is the Type Uitlener (type of loaner) which can only be two value's, Intern and Extern.

    Now the Idea is the following there a second control Element where the name of the Loaner has to been put in. Normally this input elements is choice list with typing. This will pull a list of Intern Loaners, however there is not list for the extern Loaners, so they have to be able to freely type their name.

    So in essence this means the following:

    Code:
    If lstTUI = Extern
    Then txtNUE = textcontrol typing no choice list
    Else
    TxtNUE = Combolist
    
    Click image for larger version. 

Name:	Formulier Status.png 
Views:	9 
Size:	22.4 KB 
ID:	38868

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    can cannot dynamically change a control type. What you can do is have two controls place on top of each other then depending on the uitlener value, show one or the other.

    txNue.visible=lstTut="Extern"
    cboNue.visible=lstTut="Intern"

    An alternative, more complex solution would be to build your own control combination. It might consist of a textbox, for the user to enter details, a button to represent the combo dropdown button and a list box to represent the dropdown values which appears below the textbox when required.

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    In your If statement, use the row source property set to your existing value list, otherwise leave the row source blank.
    Or, perhaps better, have a text box overlaying your combo.
    Add code so the textbox is hidden when the combo is visible and vice versa
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32
    Quote Originally Posted by Ajax View Post
    can cannot dynamically change a control type. What you can do is have two controls place on top of each other then depending on the uitlener value, show one or the other.




    An alternative, more complex solution would be to build your own control combination. It might consist of a textbox, for the user to enter details, a button to represent the combo dropdown button and a list box to represent the dropdown values which appears below the textbox when required.
    I see I will try the simple option but do I have to insert the VBA code as Form Load command, Click or change command?

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    suggest 2 places

    1. the uitlener control afterupdate event
    2. form current event so will display whatever is the right control when record is opened - or nothing for new records or where uitlener has not been populated


    you can write the code once in the uitlener afterupdate event and in the form current event put

    uitlener_afterupdate

  6. #6
    ThunderSpark is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2017
    Posts
    32
    Sorry but no further progress even doing both form Update and seperatly does not seem to work.

    Code:
    Private Sub Form_Current()
    If lstTUI = "Intern" Then
    txtNUIT.Visible = False
    lstNUIT.Visible = True
    ElseIf lstTUI = "Extern" Then
    txtNUIT.Visible = True
    lstNUIT.Visible = False
    End If
    End Sub
    Private Sub lstTUI__lstTUI_AfterUpdate()
    If lstTUI = "Intern" Then
    txtNUIT.Visible = False
    lstNUIT.Visible = True
    ElseIf lstTUI = "Extern" Then
    txtNUIT.Visible = True
    lstNUIT.Visible = False
    End If
    End Sub
    Screenshot:
    Click image for larger version. 

Name:	Result Txlst querry.png 
Views:	9 
Size:	20.3 KB 
ID:	38869

    Edit the Problem is Solved:


    Code:
    Private Sub Form_Load()
    If lstTUI__lstTUI.Value = "Intern" Then
     lstNUIT.Visible = True
     txtNUIT.Visible = False
     txtNUIT.DefaultValue = vbNullString
     Else
     lstNUIT.Visible = False
     txtNUIT.Visible = True
     lstNUIT.DefaultValue = vbNullString
     End If
    If txtstatus.Value = "Uitgeleend" Then
        lstTUI__lstTUI.Enabled = False
        lstNUIT.Enabled = False
        txtNUIT.Enabled = False
        Datum.Enabled = False
        Knop76.Enabled = False
        Knop83.Enabled = True
    Else
        txtNUIT.Enabled = True
        Datum.Enabled = True
        Knop76.Enabled = True
        Knop83.Enabled = False
        txtuitlener.Enabled = False
        txtuitlener.DefaultValue = vbNullString
        txtuitgeleendtot.Enabled = False
        txtuitgeleendtot.DefaultValue = vbNullString
    End If
    End Sub
    
    Private Sub lstTUI__lstTUI_AfterUpdate()
    If lstTUI__lstTUI.Value = "Intern" Then
     lstNUIT.Visible = True
     txtNUIT.Visible = False
     txtNUIT.DefaultValue = vbNullString
     Else
     lstNUIT.Visible = False
     txtNUIT.Visible = True
     lstNUIT.DefaultValue = vbNullString
     End If
    End Sub
    Last edited by ThunderSpark; 06-24-2019 at 07:17 AM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 10-14-2015, 01:00 PM
  2. Replies: 1
    Last Post: 11-04-2014, 12:07 PM
  3. Replies: 6
    Last Post: 10-27-2014, 08:05 PM
  4. IE element in disabled state
    By redbull in forum Programming
    Replies: 2
    Last Post: 08-12-2014, 10:02 PM
  5. Replies: 11
    Last Post: 12-25-2011, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums