Results 1 to 4 of 4
  1. #1
    bklewis is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    12

    Variable Help Needed

    I would like to assign the contents of a form field to a variable and use that variable as a query parameter when a command button is clicked on the form. So far I have not been successful at making this work. Thanks for your help!

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    It would be simplest to use the form itself in the query criteria. If you want to use a variable, you have to create a function to return its value and call the function from the criteria. You can't refer to a VBA variable directly in a query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    bklewis is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    12
    Maybe I have already done what you are suggesting. I currently have the command button set up so that it will open another form based on a query. The query parameter is directed to the field on the original form. I thought that there might be a better way to accomplish this. Doing it the way that I did I had to create 42 additional forms in my database.

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I certainly would not create 42 extra forms. I typically have 1 criteria form, used for all reports (I pass the name of the report to be opened in OpenArgs). I've also used a method where I'd copy the value to a hidden textbox on a main menu form that's always open, and have the queries point there. You might also find this method appropriate:

    BaldyWeb wherecondition
    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. Help Needed
    By vkmarty in forum Access
    Replies: 1
    Last Post: 09-23-2011, 07:23 AM
  2. Replies: 0
    Last Post: 08-10-2011, 11:59 AM
  3. Object variable or With block variable not set
    By walter189 in forum Programming
    Replies: 1
    Last Post: 07-28-2011, 08:51 AM
  4. Replies: 4
    Last Post: 08-05-2010, 01:26 PM
  5. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 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