Results 1 to 3 of 3
  1. #1
    niesenj is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    2

    Use a combo box to populate a text field

    Building a Survey database and after 2 weeks of research, brain fatigue, and building/rebuilding, I've finished my tables and am working on the user Form. Let me also mention I took two c++ classes in High School and that was it for my programming experience.

    So Basic background of function;

    The Db uses two different question tables, a general question table that is static on the survey and a specific question table relating to the course they attended.

    The two fields in the form that I am having trouble with is the combo box for picking your survey and the text box that I want to populate the Specific questions with. Right now my combo box displays the Survey Name, but populates text box with code most likely due to the " ".

    (Let me mention I am using an example for updating a 2nd combo box instead of a textbox which may not be the right direction anyway - I've tried using a subform that comes from a multiple item form, but that would require adding coding for the forms in VB code somehow.)



    I've based my design around this Microsoft post http://msdn.microsoft.com/en-us/library/bb404901.aspx

    (( Private Sub cboSName_AfterUpdate()
    ' Update the row source of the tbSpecificQuestionText Text Box
    ' when the user makes a selection in the cboSName
    ' combo box.
    Me.tbSpecificQuestionText.RowSource = "SELECT QuestionText FROM" & _
    " QtblSQuestions WHERE SID = " & _
    Me.cboSName & _
    " ORDER BY QuestionText"

    Me.tbSpecificQuestionText = Me.tbSpecificQuestionText.ItemData(0)
    End Sub ))


    I changed the RowSource around so the combo box (cboSName) displays the Names instead of the SID (PK)

    (( SELECT [tblSurveys].SName, [tblSurveys].SID FROM tblSurveys ORDER BY [SID]; ))

    Just to clarify my naming convention:

    cboSName = combo box for table tblSurveys, SName being the contained text field

    tbSpecificQuestionText = text box generated per cboSName based on the table QtblSQuestions

    QuestionText = field with questions (duh)

    SID = Pk for tblSurveys aka SurveyID

    I'm braindead now and I've tried so many options that I may have messed up what I put in here, left out some data, or just plain gave too much info.

    Thanks for the help, I'm so close to finishing this.

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Shouldn't
    Me.tbSpecificQuestionText.RowSource = "SELECT QuestionText FROM" & _
    " QtblSQuestions WHERE SID = " & _
    Me.cboSName & _
    " ORDER BY QuestionText"
    be
    Code:
    Me.tbSpecificQuestionText.RowSource "SELECT QuestionText FROM" _
    " QtblSQuestions WHERE SID = '" _
    Me
    .cboSName _
    "' ORDER BY QuestionText" 
    Note the added tic marks.

  3. #3
    niesenj is offline Novice
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    2
    I will try that monday, thanks.

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

Similar Threads

  1. Auto-Populate Combo box
    By vincenoir in forum Forms
    Replies: 3
    Last Post: 10-14-2009, 07:06 AM
  2. IIF statement to populate field
    By GriffyNJ in forum Queries
    Replies: 0
    Last Post: 10-13-2009, 10:07 AM
  3. populate the same named field in two subforms??
    By jhjarvie in forum Programming
    Replies: 1
    Last Post: 09-25-2009, 04:34 AM
  4. Replies: 2
    Last Post: 05-22-2009, 01:07 PM
  5. Populate Combo Box
    By wes28 in forum Programming
    Replies: 1
    Last Post: 03-04-2009, 06:45 AM

Tags for this Thread

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