title: Populate Text box on access form based on the value of combo box on the same form
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3786993/msaccess-populate-text-box-with-value-from-query">MSAccess - populate text box with value from query</a>  </p>
  </blockquote>
  
  
  
  <p>I have a  single form on which there exists several combo boxes and text box. one combo box value (for the Wells) will be filled independently, then I needs the text box to have its value based on the value of the wells combo box value.
  I have created a query that solved the propblem partially, it requires parameter which the wells combo box value. If I ran with query a part from the form, it wroks good and asks for the parameter and it is OK.
  I do think to make use of VBA, adding a code which process a SELECT statement (of the query mentioned above), then to tell it to take its parameter from the wells combo value which will ready on the form.</p>
  
  <p>Can someone help on this. Can this works as I descriped.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Mohamed</p>
  
  <p>Further to my question above, I have tried the following solution:</p>
  
  <pre><code>   Private Sub Well_ID_Change()
  Last_Ref.ControlSource = " SELECT TOP1 New_Ref FROM" &amp; _
  " BSW_Transactions WHERE BSW_Transactions.New_Ref Is Not Null AND BSW_Transactions.Well_ID = " &amp; Me.Well_ID.Value &amp; _
  " ORDER BY BSW_Transactions.Sample_Date DESC"
  End Sub
  </code></pre>
  
  <p>the Last_Ref is the text box I want to fill in with result of the embedded SELECT statement in the code. The Well_ID is the combo box which value will be the parameter of the SELECT statement. The Well_ID is number field and it displays the well_name and stores the associated ID value in the table. Upon running the  form after saving changes, the Last_Ref text box showed (#Name?). I guessed that the text box (is a number field) found a text in the combo box Well_ID, so I added ".Value" to the above syntax at the criteria Me.Well_ID. However the problem still exists.</p>
  
  <p>May I mistaken in the syntax, would someone help on this. Can this works fine?</p>
  
  <p>Thanks in advance.
  Mohamed </p>