Results 1 to 12 of 12
  1. #1
    oleander is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2017
    Posts
    16

    Using a Macro to Enter Text into an Input Box

    Hi everyone!



    I have a report in access that asks for two criteria to complete the query before running the report. What I want to do is create a form with buttons for all the different combinations of text that could be entered so that when you click on a button, it'll automatically complete the query and generate the report. Is that possible?

    Thanks!

  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,652
    Sure. I'd use VBA but a macro would also work. A macro would use SetValue or SetProperty. In VBA

    Me.TextboxName = "Your text here"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    oleander is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2017
    Posts
    16
    Hmm. I tried using SetProperty to with the values being what I wanted entered in the pop up, but when I clicked the button nothing happened. The input box just popped up like normal and the macro stopped.

    If I try the VBA, how do I know what the name of the pop up box is?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Sorry, I meant that you would have the macro/code populate a textbox on the form, and you'd point the query to that textbox rather than use bracketed criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    oleander is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2017
    Posts
    16
    Oh, interesting! I think I see what you're saying. I'll give that a shot!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Most of us use forms to gather user input. You have a lot more control than using bracketed parameters.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    oleander is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2017
    Posts
    16
    So, I guess the next question is, what exactly do I put in the criteria in the report query? I set up the button so that it puts the text I want into the textbox, and I've gone into the query and used the builder to put in...

    [Forms]![FormWithTextBox]![TextBoxName].[Text]

    But I'm not sure if the .[Text] at the end is correct? When I use that and save everything, the report isn't coming up with the right data.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No, you don't want the text at the end. Try

    [Forms]![FormWithTextBox]![TextBoxName]

    changing the names of course. See here for more on the text property, if you're bored:

    http://www.baldyweb.com/ValueText.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    oleander is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2017
    Posts
    16
    Hmm, nope, that doesn't seem to do it either.

    The values I want are definitely showing up in those text boxes, and I have the string with the correct names of the form and the text box set in the criteria, but the report just doesn't show any data.

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    oleander is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2017
    Posts
    16
    Oh my god I'm an idiot. I was using a criteria to test everything out that usually we have data for but don't currently. Which is why nothing was showing up.

    It works fine now. Thank you for your help!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    We've all done it! Glad you got it working, and welcome to the site by the way!
    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: 1
    Last Post: 09-01-2017, 10:28 AM
  2. Replies: 7
    Last Post: 01-02-2016, 09:49 AM
  3. How to run a macro when enter pressed on a form?
    By behnam in forum Programming
    Replies: 1
    Last Post: 05-26-2014, 08:41 AM
  4. Enter Parameter Value Error in Macro
    By kasimagj in forum Programming
    Replies: 3
    Last Post: 09-19-2011, 03:53 PM
  5. Replies: 8
    Last Post: 09-24-2009, 02:56 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