How to Create Selective Autofill TextBoxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BioDev
    New Member
    • Oct 2011
    • 2

    How to Create Selective Autofill TextBoxes

    Hey guys, I am new to Access and am wondering how one might go about programing a form that will auto-fill information into a TextBox when a specific record is selected from a ComboBox, but when no record is selected allow me to put in new information.

    I am designing a database that tracks contracts between medical institutions (facilities) and a university. Some facilities have the same contract information because they are owned by the same parent company, while others have no parent company, therefore unique information. I'd like to be able to have the contract information from facilities, who have the same contract information, to be auto-filled by selecting a value from a ComboBox that lists all of the parent companies, but still have the ability to input new information myself for facilities who have no parent.

    I have tried using If Then Else statements with no success. If anyone has an idea of how I should go about creating this it would be very much appreciated as I have reached the the limits of my knowledge about Access.
    Last edited by NeoPa; Oct 28 '11, 11:24 PM. Reason: Rewrote to be legible.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32653

    #2
    On your form you could have a ComboBox (We'll call [cboParent]) and a TextBox (We'll call [txtContract]).

    [txtContract] might start, by design, as unlocked and empty. [cboParent] would need to have a list of parent companies and associated contract information, as well as an entry reflecting no parent (where the contract information part would be blank). Assume for now, that the the entry for no parent company holds the string value "None".

    In the AfterUpdate event procedure of [cboParent] place the contract information (using the Column() method) into [txtContract]. Next compare the value of [cboParent] with "None" and set the .Locked property of [txtContract] based on that.

    The code would be similar to :
    Code:
    Private Sub cboParent_AfterUpdate()
        With Me
            .txtContract = .cboParent.Column(Index:=1)
            .txtContract.Locked = (.cboParent <> "None")
        End With
    End Sub

    Comment

    • BioDev
      New Member
      • Oct 2011
      • 2

      #3
      Thanks NeoPa! I have been stuck on that one for awhile.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32653

        #4
        Pleased to help :-)

        Comment

        Working...