Results 1 to 6 of 6
  1. #1
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41

    Select error

    hi guys, i write a sql code to display a value in table by textbox valuin form, but i get error for this :





    weight22 = "select weight from tbl_matter where matter1 = " & Me.matter2 & "

    weight22 is field name on my form that i want to display weight from tbl_matter and matter2 is textbox field in the same form too.

    can someone provide the correct method to use???

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    try not to use sql , instead use queries, text boxes do not get sql, the form does.
    but if matter2 is numeric , then you dont need delimiters:

    weight22 = "select weight from tbl_matter where matter1 = " & Me.matter2

    if it IS text then you need quotes:
    weight22 = "select weight from tbl_matter where matter1 = '" & Me.matter2 & "'"

  3. #3
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    thanks for reply, matter2 is text and i run second sql code, but this time i get this error :

    Click image for larger version. 

Name:	Screenshot (524).png 
Views:	15 
Size:	5.5 KB 
ID:	32859

    matter2 type is text and weight,weight22 are of double type.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Show us your table design.
    As ranman suggests, use a query.
    You can test your logic with a query, before designing to use form.

    Code:
    SELECT  weight from tbl_matter where matter1 =[Enter a matter1 value]
    example: entering "c" gives
    weight
    21.99

    with this table

    id matter1 weight
    1 a 12.45
    2 b 34
    3 c 21.99
    4 d 157.59
    5 e 34.91

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can't pull a value into textbox by referencing an SQL string. All it does is try to pull the string into textbox. Why are you doing this? If you need to pull value from another table, options:

    1. a multi-column combobox that includes the field then code can reference column of combobox

    2. include the table in the form's RecordSource to retrieve the related data, bind textbox to the weight field and set it Locked Yes and TabStop No

    3. DLookup() expression in textbox or in VBA: weight22 = DLookup("weight", "tbl_matter", "matter1 = '" & Me.matter2 & "'")

    Regardless of which option used to display the value, code is required to save to record. But why save the value when it can be retrieved through query join?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    civl_eng is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    41
    thanks guys, i have several text box in a form and i wanted to pull string into textbox from another table and i did not want to create query for each table and text box for this reason i used SQL instead query and i got error for this, now i use June7 code (Dlookup) and my problem has been resolved.

    sorry for my poor english.
    thanks again for your reply.

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

Similar Threads

  1. Error In Select Case Statement
    By archie1_za in forum Programming
    Replies: 11
    Last Post: 12-05-2017, 03:26 AM
  2. Select Case Error
    By LaughingBull in forum Access
    Replies: 13
    Last Post: 09-11-2015, 02:05 PM
  3. Syntax error on VB Select Where Clause
    By FrustratedAlso in forum Programming
    Replies: 3
    Last Post: 01-30-2014, 02:57 AM
  4. Access2007 error 3075 execute SELECT
    By candide in forum SQL Server
    Replies: 1
    Last Post: 04-24-2013, 08:31 AM
  5. SELECT INTO Error
    By Tyork in forum Queries
    Replies: 3
    Last Post: 02-03-2011, 12:43 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