Results 1 to 3 of 3
  1. #1
    mark71 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    3

    Pass Variable textbox to query (Access 2010 - VBA)

    Hi,
    I've created in VBA an USerform named (form1) in which I've put one textbox1 and one clickbutton.



    After fill textbox1 with a value and push clickbutton I would like to run this query based on fact that the variable in textbox1 is passed to SQL string , currently it doesn't work.

    RS.Open "SELECT * FROM [VENDOR DATA] WHERE [Buyer]=Forms!Form1!textbox1.value"

    The form has been created in VBA development area instead of automatic form on Access main application.

    Do you have suggestion ?

  2. #2
    mercapto is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jan 2012
    Location
    Spain
    Posts
    91
    The value of the textbox cannot be inside a string("...").

    The code should be somethig like:

    Code:
    Dim strSQL as string
     strSQL = "SELECT... WHERE [Buyer] = " & Me.textbox1
    rs.open strSQL
    Hope it helps

  3. #3
    mark71 is offline Novice
    Windows Vista Access 2010 32bit
    Join Date
    Dec 2012
    Posts
    3
    It works! thanks!

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

Similar Threads

  1. Replies: 0
    Last Post: 02-07-2012, 04:38 AM
  2. Replies: 4
    Last Post: 01-03-2012, 08:11 PM
  3. VBA Pass-through Query with Variable
    By smaumau in forum Programming
    Replies: 0
    Last Post: 12-06-2010, 09:10 AM
  4. Variable Report Title in Access 2010
    By Titan078 in forum Reports
    Replies: 4
    Last Post: 11-17-2010, 11:22 AM
  5. Replies: 5
    Last Post: 04-05-2010, 11:43 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