Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2010
    Posts
    29

    Unanswered: Populate text boxes with a command button

    I want to populate two text fields from a combobox with a command button to enter into text boxes in my form.

    The combobox is getting it's info from tblcommitteeinfoentry. The two fields are PI and RDOfficeStudyNo.

    The form name is Frmconsenterror and to populate the table called consenterrors with fields named PI and studyno.


    Thanks for the help!

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Rather than using a Command Button, this is normally done by simply making a selection from the Combobox and assigning the values using its AfterUpdate event.


    1. Place a Combobox on your form.
    2. When the wizard comes up select "I want Combobox to look up values in a table/query"
    3. Select tblcommitteeinfoentry
    4. Click to move PI to right hand box
    5. Click to move RDOfficeStudyNo to right hand box
    6. Sort by whichever Field is appropriate
    7. Select Remember Value for Later Use
    8. Chose caption for the Combobox (if desired)
    9. Click Finish


    Now, in the AfterUpdate event for your Combobox
    Code:
    Private Sub YourComboBox_AfterUpdate()
      Me.PI = Me.YourComboBox.Column(0)
      Me.studyno = Me.YourComboBox.Column(1)
    End Sub
    and Bob's your uncle! Replace YourComboBox with the actual name of your Combobox, and notice that the Column Index is Zero based.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Nov 2010
    Posts
    29
    How do I incorporate the command button to enter the data from the combobox to the text boxes? Thanks!

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by Brian62 View Post
    How do I incorporate the command button to enter the data from the combobox to the text boxes?
    You don't need a Command Button! When you make a selection from the Combobox the data will be automatically placed in the Textboxes.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2010
    Posts
    29
    The problem I see with that is if they accidently select something from the combobox then the data in the text boxes will change. With the command button they will have to select enter to enter the data into the check boxes thus making the changes. I will have a message popup so they will have to confirm that is what they want to do.
    I hope that makes sence. Thanks!

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    So if they make a mistake in their selection, they merely make a new selection (which they'd have to do, regardless of how you handle it) and the new data would be inserted into the Textboxes! The general idea in programming is to make the users do as little work as possible, and in most cases, a Button would increase the work.

    At any rate, the same code
    Code:
    Me.PI = Me.YourComboBox.Column(0)
      Me.studyno = Me.YourComboBox.Column(1)
    will work if placed behind a Command Button.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Nov 2010
    Posts
    29
    I got it to work but when I go to the next record the same info appears in all records.

    The combox is named Combo59 and the command button is named Command67, if that helps.

    This is the code I used.

    Private Sub Combo59_Click()
    Me.PI = Me.Command67.Column(0)
    Me.StudyNo = Me.Command67.Column(1)
    End Sub
    Last edited by Brian62; 09-30-11 at 17:37.

  8. #8
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by Brian62 View Post
    I got it to work but when I go to the next record the same info appears in all records...
    When the same data appears in a given Control, on all Records, it means that the Control is not Bound to a Field in the underlying Table/Query. To be Record-specific it must be Bound!
    Quote Originally Posted by Brian62 View Post
    ...The combox is named Combo59 and the command button is named Command67, if that helps.

    This is the code I used.

    Private Sub Combo59_Click()
    Me.PI = Me.Command67.Column(0)
    Me.StudyNo = Me.Command67.Column(1)
    End Sub
    There's no way that code could work! You've crossed up your Controls, probably because you're using the nasty habit of not re-naming the Controls so that they have some meaning!

    You're using the Click event of your Combobox, Combo59 and assigning values from your Command Button, Command67, to Controls on your current Form! Command Buttons have neither Data nor Columns!

    Assuming that you're trying to use the Click event of the Command Button, your code would be
    Code:
    Private Sub Command67_Click()
        Me.PI = Me.Combo59.Column(0)
        Me.StudyNo = Me.Combo59.Column(1)
    End Sub
    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    Join Date
    Nov 2010
    Posts
    29
    Got it to work! Thanks a bunch and have a great weekend!

  10. #10
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad you got it working!

    Good luck with your project!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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