Results 1 to 1 of 1

Thread: Resolved :Query created with code

  1. #1

    Thread Starter
    Member
    Join Date
    May 2005
    Posts
    56

    Resolved Resolved :Query created with code

    Hello all,

    Here is the code that I am trying to use that will create a query depending
    on which form fields are populated.
    VB Code:
    1. Dim C As Access.Control
    2.   Dim sC As Variant
    3.   Dim Qdef As DAO.QueryDef
    4.   Dim Db As DAO.Database
    5.  
    6.     sC = Null
    7.     Set Db = Access.CurrentDb()
    8.     Set Qdef = Db.QueryDefs("QryBlank")
    9.     Qdef.SQL = "SELECT * FROM TblClientData A"
    10.    
    11.     For Each C In Me.Controls
    12.         If TypeOf C Is Access.TextBox Or TypeOf C Is Access.ComboBox Then
    13.             If VBA.InStr(C.Tag, "Criteria") > 0 And Not VBA.IsNull(C.Value)
    14. Then
    15. sC = (sC + " AND ") & "[" & C.Name & "] Like '*Forms![" & Me.Name & "]! _
    16. [" & C.Name & "]*'"
    17.             End If
    18.         End If
    19.            
    20.     Next
    21.     If Not VBA.IsNull(sC) Then Qdef.SQL = Qdef.SQL & " WHERE " & sC
    22.  
    23. End Sub
    I am not sure what I am doing wrong but when I run this code and then go
    look at the query in sql view all that is there is this:

    SELECT *
    FROM TblClientData AS A;

    The query shows everything on the table whether I populate the text boxes on
    the form or not.

    Couple of things that I am not sure if they make a difference. I do not have
    a control source for my form and for the c.tag property I assume that is the
    same thing as smart tag when I look at the controls property under data.
    Thanks for any insight you can offer.

    James O
    Last edited by Hizaed; Mar 17th, 2006 at 12:48 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
  •  



Click Here to Expand Forum to Full Width