Results 1 to 11 of 11
  1. #1
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30

    how to include values of text boxes in queries

    Hi, how do i use the values of text boxes in queries?
    I used the code below.

    Code:
    INSERT INTO AdviserTable ( IDNumber, LastName, FistName, FullName )
    VALUES ("+txtIDAdviser.text+", '+txtLastAdviser.text+', '+txtFirstName.text+', '+txtLastAdviser.text+, +txtFirstAdviser.text')
    Whenever i run the code, a form with the columns Expr1000, Expr1001, Exper1002, Exper2003 containing the values +txtIDAdviser.text, +txtLastAdviser.text+, '+txtFirstName.text+' , and '+txtLastAdviser.text+, +txtFirstAdviser.text appears. What's wrong with my code?

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Here is a small example:

    I have a Table tblIn_Out_Details.

    I have used value entered in Text0 , Text2 in the Form1:

    INSERT INTO tblIn_Out_Details ( Dealer_Customer, Details )
    VALUES ([Forms]![Form1]![Text0], [Forms]![Form1]![Text2]);

    if this solves your problem mark the thread solved

  3. #3
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30
    hi, it appears that [Forms]![Form1]![Text0], [Forms]![Form1]![Text2] uses pop-ups to get data from the user. what i want to do is get data from existing textboxes

  4. #4
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    You need to change the Form1 and Text0, Text2 names in LAazsx's example to what your form name and text box name is.

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    LAazsx's example ? Did you get the name wrong here LOL

  6. #6
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30
    Yeah. I changed the values. Pasted the wrong one. Anyway, I want to combine the value of two texboxes into a single string. I'm guessing something like
    Code:
    VALUES (Forms![New Adviser]![IDNumber] "," Forms![New Adviser]![FullName]);
    but and error occurs. what's the proper way to include "extra" characters? I what the output to be IDnumber, Fullname

  7. #7
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I have a Form2 FirstName Typed in TextBox0 and LastName Typed in TextBox2. I have combined them together to Insert The value into my Table1 Field TName.

    INSERT INTO Table1 ( TName )
    VALUES ([Forms]![Form2]![Text0] & " " & [Forms]![Form2]![Text2]);

    Please make sure u put the names of you Form, Controls, Table etc.

    Please be more specific what you want to do this will help us to help you accurately.

  8. #8
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30
    Sorry. Uhm.. I have a form with the fields FirstName and LastName. When the AddRecord button is clicked, a query will be run. the query will combine the values of the two textboxes and place a ", "between them.

    Code:
    INSERT INTO AdviserTable (  FirstName, LastName, FullName )
    VALUES ([Forms]![NewAdviser]![FirstName], [Forms]![NewAdviser]![LastName], [Forms]![New Adviser]![LastName] & ", " & [Forms]![New Adviser]![FirstName]);
    I tried using this query but when it is run, a pop up comes up and when i fill out the fields, the FullName column isn't populated.

  9. #9
    pkstormy's Avatar
    pkstormy is offline Access/SQL Server Expert
    Windows XP Access 2003
    Join Date
    Mar 2010
    Location
    Madison
    Posts
    682
    Quote Originally Posted by maximus View Post
    LAazsx's example ? Did you get the name wrong here LOL

    Yes I looked at the wrong post. Sorry about that maximus.

  10. #10
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Just when I thought that I will see a green halo encircling this thread header you have managed to come up with yet another problem LOL.

    Here is the Query:

    INSERT INTO Table1 ( FirstName, Lastname, FullName )
    VALUES ([Forms]![Form2]![Text0], [Forms]![Form2]![Text2], [Forms]![Form2]![Text0] & ", " & [Forms]![Form2]![Text2]);

    To be on the safe side I am including a sample with this reply.
    1) Open Mdb file.
    2) Type FirstName
    3) Type LastName
    4) Click Command Button Run Query
    5) Check Table1 for the results.
    6) Query1 is the Append Query.

  11. #11
    LAazsx is offline Advanced Beginner
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Nov 2010
    Posts
    30
    Thanks for the reply. Well my main problem here is that i can't get anything to write into the Fullname column. It works now. The reason why I can't get to work is because my textbox was bounded (LMAO). I've unbounded it now.

    New problem: Whenever the query is run, a pop up required me to re-enter the values. As if it doesn't recognize or know that there are existing textboxes with values.

    I tried copying your button and code exactly but still the same. Something to do with form settings maybe? I compared them side to side but there are no difference which are not design related.

    Edit: Got it to work now. Didn't really know what I did since i did a bunch of things. I'll just try to find out what it was. Thanks for your time.

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

Similar Threads

  1. Replies: 11
    Last Post: 10-06-2010, 12:19 AM
  2. Replies: 15
    Last Post: 09-18-2010, 01:19 PM
  3. include zero data where no record
    By Sandy Gomez in forum Access
    Replies: 4
    Last Post: 09-15-2010, 06:23 AM
  4. Replies: 1
    Last Post: 03-27-2010, 06:13 AM
  5. joining text in text boxes
    By jjwilliams73 in forum Forms
    Replies: 1
    Last Post: 08-26-2008, 02:30 PM

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