Results 1 to 3 of 3
  1. #1
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194

    Passing form txtbox.text to vba variable then to query criteria!

    Hey everyone,



    So I have a query criteria:

    Like [Forms]![People]![Textbox].text

    but this query runs in a different form than this textbox.

    I also want to change this variable on the query depending on the form im using.

    My understanding is that i can use a VBA Function in my query.

    SO,,,, My idea is something like this (bear with the fact that im VERY new to vba coding, im trying to learn them :S

    Code:
    (In top of module)
    Dim txtbx as string
    
    Private sub on_click
    
    txtbx = me.textbox.text
    
    end sub
    
    
    
    
    in next form (the one with the query)
    
    public function frmtxtbox()
    frmtxtbox = txtbx
    end sub
    Then in my query criteria i can write... Like frmtxtbox() & "*"


    Am i on the right track??
    Last edited by June7; 07-01-2015 at 11:34 AM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Looks like it should work (I wouldn't use the .Text property though). Did you try it?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    The variable txtbox is declared behind one form but cannot be seen by other form code.

    If you want variables seen by multiple modules, must be declared as public in a general module.

    Unless you want txtbox variable used by several forms, the Sub is not really needed. A function must have End Function, not End Sub. VBA should automatically correct that.

    Public Function frmtxtbox()
    frmtxtbox = Forms!People.Textbox
    End Function

    I NEVER use dynamic parameterized queries. I prefer: http://www.allenbrowne.com/ser-62.html
    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.

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

Similar Threads

  1. Replies: 9
    Last Post: 05-30-2012, 12:57 AM
  2. Variable Not passing to query
    By chris.williams in forum Queries
    Replies: 2
    Last Post: 10-14-2011, 08:30 AM
  3. Passing Form Variable to Query
    By allenrickson in forum Reports
    Replies: 10
    Last Post: 06-27-2011, 07:33 PM
  4. Passing form fields criteria to a Query
    By yosik20 in forum Queries
    Replies: 1
    Last Post: 05-12-2011, 04:24 AM
  5. Passing a variable to a form
    By cjamps in forum Forms
    Replies: 0
    Last Post: 03-02-2009, 05:32 AM

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