home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / access / diverses / qbf / qbf.txt < prev    next >
Text File  |  1995-01-30  |  7KB  |  153 lines

  1. 1/30/95
  2.  
  3.  
  4. For more complete information on the use of this Query-by-Form code see the
  5. article in the February/March issue of "Access/Visual Basic Advisor" titled
  6. "QBF, Generic Blackboxes and Gold-Plated Trophies".
  7.  
  8. To get a feel for what the QBF is capable of doing, open the enclosed MDB and
  9. open the form called fdlgOrderInformation.  The sample tables comes from the
  10. Orders.mdb that shipped with Access 2.0; there are 1,082 joined records in the
  11. result set.  Enter sample criteria to any of the fields.  You may use a list
  12. separator character (comma, by default) to specify as many disparate items as
  13. you wish in a particular field.  Or you may enter a range of values, such as ab
  14. - ca or $1,000 - $1,500.  At this time, ranges and lists cannot be used within
  15. the same field.  When the query is built, default operators will be used if one
  16. is not explicitly stated.  Character data operators default to "Like"; numeric
  17. and dates to "=".  With dates there are several directives that can be used as
  18. the criteria:  today, yesterday, tomorrow, month, mth, year, yr, fiscal year,
  19. FY, FYTD; previous, last or next can precede many of these special directives;
  20. abbreviations are supported in some cases.  The logical operator "Not" is
  21. supported, and most of the special SQL operators will be passed through if used
  22. ([!a-c] is valid, for example, as is Not [a - t]).  Synonyms are valid in many
  23. cases; "!" is valid in lieu of "Not".  White space is usually ignored.  All in
  24. all the model has been designed to be very forgiving of the user; I have tried
  25. to develop a syntax that would be reasonably straightforward to use with a
  26. minimal amount of training.  Here are some examples of the type of entries you
  27. can make to the QBF (this is by no means a complete list):
  28.  
  29.  
  30. If the user enters...        This SQL expression is produced...
  31. =====================        ==================================
  32.  
  33. Acme                         fieldname Like "Acme*"
  34.  
  35. Not Like Acme*               fieldname Not Like "Acme*"
  36.  
  37. Acme - Lucky                 fieldname >= "Acme" AND fieldname <= "Luckyzz"
  38.  
  39. Acme, Lucky, Safe            fieldname Like "Acme*" OR fieldname
  40.                              Like "Lucky*" OR fieldname Like "Safe*"
  41.  
  42. = Acme Inc.                  fieldname = "Acme Inc."
  43.  
  44. >= Acme                      fieldname >= "Acme"
  45.  
  46. Null                         fieldname IS NULL
  47.  
  48. 1,025.50 - 2,500             fieldname >= 1025.50  AND fieldname <= 2500
  49.  
  50. $13, 25.50, 1000.50          fieldname = 13 OR fieldname = 25.50 OR
  51.                              fieldname = 1000.50
  52.  
  53. >= 10,000                    fieldname >= 10000
  54.  
  55. -10,000 : -5,000             fieldname >= -10000 AND fieldname <= -5000
  56.                              Assumes range-specifier character changed to
  57.                              a colon.
  58.  
  59. 10/20/94                     fieldname = #10/20/94#
  60.  
  61. 10/20/94 - 01/10/95          fieldname >= #10/20/94# and fieldname
  62.                              <= #01/10/95#
  63.  
  64. 10/93                        fieldname >=  #10/1/93# AND
  65.                              fieldname <= #10/31/93#
  66.  
  67. < 10/25/92                   fieldname <= #10/25/92#
  68.  
  69. 91                           fieldname  >= #01/01/91# AND
  70.                              fieldname <= #12/31/91#
  71.  
  72. 03                           fieldname >= #03/01/94# AND
  73.                              fieldname <= #03/31/94#   Assumes month
  74.                              entered and uses current year.
  75.  
  76. Today                        fieldname = #today's date#
  77.  
  78. ...and all the other special date directives mentioned above.
  79.  
  80. If you have questions as to whether an alternative syntax might be supported,
  81. either try out your suspicion or browse through the code (the former is *much*
  82. easier than the latter).
  83.  
  84. Here is what you need to do to put this routine to work.  It is possible to set
  85. up a QBF in under ten minutes.  The easiest way to get started is to open the
  86. included dialogue form called fdlgOrderInformation and do a Save As to a file
  87. name of your choice, and then proceed to make changes to your controls and
  88. labels as described below.  This way you will automatically be able to take
  89. advantage of all of the extended functionality of this QBF model.
  90.  
  91. 1. Create a form of the dialogue type (unless you are using my sample as
  92. a starting point). Dialogue forms stop all other processing within the
  93. application, and are useful for tasks that must be accomplished before
  94. some other task is initiated. Obviously in this case, the user must enter
  95. criteria before the main form or report is executed.
  96.  
  97. 2. Place any number of unbound controls on your form for accepting
  98. user criteria; label each of these fields. A control is unbound if the
  99. controlsource property is left empty.
  100.  
  101. 3. Place the name of a previously saved query in the tag property of your
  102. QBF form. This querydef will provide the basis for the filter string that
  103. the QBF builds. The name should be inserted as follows, substituting
  104. your actual querydef name: RecordSource: "your querydef name" .
  105. The colon or other connecting characters are immaterial; the quotes
  106. are necessary. One caveat: In order for the QBF to successfully
  107. modify your querydef SQL statement, the where clause of your
  108. querydef should be altered to read WHERE FALSE.
  109.  
  110. 4. For each control that you would like to be considered in the query,
  111. open the property sheet for the unbound control and place the
  112. following directive in the control's tag property substituting your table
  113. and field name: QueryField: "tablename.fieldname". Double quotes
  114. must be used around the value. This information is stored in the tag so
  115. that the generic QBF routine can later determine the data field against
  116. which the user-entered criteria should be compared.
  117.  
  118. 5. If you would like your QBF to interactively build the Where clause so that
  119. the user can view the SQL as he/she tabs from field to field, then you must
  120. include the following in each criteria field's After Update event property:
  121. =MakeQuery(screen.activeform).
  122.  
  123. 6. Create a push-button (or a control of your choice) which will have
  124. attached to its click event a procedure that calls the following function
  125. with a single parameter indicating the current form object:
  126. =MakeQuery(screen.activeform).
  127.  
  128. 7. Lastly, you should include on your form a text box called
  129. txtNewSQL, and make the control not visible. This is where the
  130. generic QBF will dump the newly created SQL string. You can take
  131. this newly created SQL string and do any number of things with it.
  132. Most likely you will want to pass it to the record source of your
  133. primary form or to the record source of a report.
  134.  
  135. The routine has been designed to deal with the absence of many of the above
  136. mentioned components.  For example, if the preview screen forms or the Show SQL
  137. form do not exist, this routine will continue to work.
  138.  
  139. The QBF does much, much more than I have indicated in this brief note. A great
  140. deal of this is discussed in the full article. The remainder still needs to be
  141. documented. For now, besides the article, there's the code, and lots of it.
  142.  
  143. I am beginning work on optimizing this model for the client-server environment,
  144. where selective querying obviously has its very strong merits.
  145.  
  146. Please feel free to comment. There's lots of room for improvement.
  147.  
  148.  
  149. Craig Lyall
  150. DiMento/Lyall, Inc.
  151. Oakland, CA
  152. 70731,2704
  153.