Results 1 to 3 of 3
  1. #1
    classicmds is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    1

    Parameter query using form textbox problem

    I have had a very simple parameter query based on a form working fine until I made a few changes to the design, and now it does not work. I decided to started a whole new database with test forms to strip it back, and it doesn’t work there either. It's been a long time since I worked on this, and I only have very basic Access knowledge, but I'm pretty sure I've got it right based on online info... But am I doing something wrong?! Thanks.





    • I have Test Form with an unbound text box named “Last Name”
    • I have a Test Table with two fields “Last Name” and “First Name”
    • I have a Test Query with the Test Table added. I have added the fields “Last Name” and “First Name” from the Test Table to the query.
    • In the criteriia for “Last Name” I have [Forms]![Test Form]![Last Name]
    • I have the Test Form open and a last name that is stored in the Test Table typed into the “Last Name” field of the form.
    • I run the query. It returns no results. I am expecting it to return the record containing the last name typed into the Test Form, and the query to use this as the criteria.
    • If I just type in the last name direct to the query criteria it finds it. So the problem is the query is not using the data in the Test Form as the criteria

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    If you are using BOTH text boxes to search then heres the thing:
    if you search just one box (last or first) then you cannot use the other in the query.
    BEST approach:

    make a continuous form that shows ALL records.
    the header has the 2 textboxes, txtFirst, txtLast
    then put in a button to FILTER the data. It will look at both boxes, then set the filter for 1 or both:
    Code:
    '----------------
    sub btnFilter_click()
    '----------------
    dim sWhere as string 
    
    
    sWhere = "1=1"
    if not IsNUll(txtFirst) then sWhere = sWhere & " and [First]='" & txtFirst & "'"
    if not IsNUll(txtLast) then sWhere = sWhere & " and [LAST]='" & txtLast & "'"
    
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Make sure you've hit Tab or Enter after typing the name. If you don't, the value isn't available to the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 03-31-2017, 03:04 PM
  2. Passing a Form Textbox to a query parameter
    By NickWren in forum Access
    Replies: 2
    Last Post: 06-28-2016, 08:43 AM
  3. Passing textbox value into sql query parameter
    By gustavoavila in forum Access
    Replies: 7
    Last Post: 04-23-2014, 04:00 PM
  4. Parameter query problem
    By chrisfl in forum Queries
    Replies: 1
    Last Post: 08-17-2013, 12:06 AM
  5. Query with parameter from Form Textbox
    By Juan4412 in forum Queries
    Replies: 1
    Last Post: 07-10-2013, 02:33 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