Results 1 to 9 of 9
  1. #1
    Join Date
    May 2004
    Posts
    144

    Unanswered: Fill A text box control with a select value

    i insert a txt box into a form & want to fill it with something like this:

    SELECT string FROM tblStrings WHERE id=1;

    how i should insert this statement value in my txtbox?

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Is it going to be related to some other control on the form? Could you make the other control a combo box that pulls the extra data?
    Then your control source for the new field would be something like:
    =cmbField1.Column(1)
    Inspiration Through Fermentation

  3. #3
    Join Date
    Nov 2009
    Posts
    49
    Hi,

    You could probably just put that code into the Control Source of that particular textbox

    Phil

  4. #4
    Join Date
    May 2004
    Posts
    144
    pb190, it not working.
    maybe i must explain it with more details.
    i have a tblStrings that all the labels value in my app is in there. for filling every label i want to use one of these strings like this:
    SELECT string FROM tblStrings WHERE id=1;
    i have try everything in txtbox control source, but i did not work out.

  5. #5
    Join Date
    Nov 2009
    Posts
    49
    Are you physically putting this string:

    SELECT string FROM tblStrings WHERE id=1;

    into the record source of the txtbox, if you are then the problem would be the WHERE clause, SQL isn't that clever to know where id is, so you will have to include the pathway for it e.g. Forms![YourForm]!ID.value = "1" or however it is.

    Also I think this setup is a little confusing, so could you explain the procedure, almost flow diagram ish, on what is meant to happen.

    E.g. Click on a label -> label has a certain value found in tblStrings -> value is displayed in textbox.

    Phil

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try this, in the Form Current event for instance, or wherever you need it:
    Code:
    Me.TextBox.Value = Dlookup("string", "tblStrings", "id = 1")
    Have a nice day!

  7. #7
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You can't use a SQL statement as the control source for a text box. You can use a field, or an expression. The field would come from the record source for the form, and an expression can be something like =DateAdd("d",7,Now()) or what Sinndho offered above: = Dlookup("string", "tblStrings", "id = 1")
    Inspiration Through Fermentation

  8. #8
    Join Date
    May 2004
    Posts
    144
    tanks guys, dlookup worked out.
    another general question is why i must put between parameteres in access functions semi-col(? coma(,) not working despite in access help all the functions come with coma?

  9. #9
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Are you operating in a country where English is the normal language? In some countries different delimiters are used, but Access Help generally assumes you're using the English version.

    BTW, string is a Reserved Word in Access and sooner or later you're apt to run into problems because of this. You need to change it to something else, even if you simply add an s to make it become strings.
    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
  •