Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    41

    Question Unanswered: Public variable as query criteria

    I'm sure I must be missing something obvious but ....
    I have a customer table with two fields, Name(text) and ID(integer). I have declared a public variable, mCustomer as integer in a standard module. In a form I set the value of mCustomer. I also have a query with mCustomer as the criteria for the ID field. Seems simple so far. In the immediate window I can retrieve the value of mCustomer but when I run the query a window pops up asking for the value of mCustomer. What's wrong? Are public variables not available to queries? Whats the point of a variable if it can't be passed to a query?

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    use a public function that returns the value of your public variable.
    currently using SS 2008R2

  3. #3
    Join Date
    Apr 2004
    Posts
    41

    Yes I discovered that but

    I don't understand WHY that is necessary.

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Well, I suppose you could view it as queries are written in SQL, functions are written in VBA. It's much easier to implement a platform that will allow you to call a vba function to return values then it is to completely integrate the two.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •