Results 1 to 4 of 4
  1. #1
    Rajeshsms is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    3

    Form Query

    Dear all,



    I have this form that takes 4 query fields. I was only able to program one. I need to add the other 3 as well. One is a text field and the other 3 are called cbmsecurity , cmbcategory etc. I dont know the syntex.

    Should it be str = "SELECT Notes.ID, Notes.[Expanded Number], Notes.Title, Notes.Date, Notes.[Security Level] FROM Notes WHERE ((((Notes.Title) Like '*" & Me.txtTitle & "*' ))) AND (((Notes.Category) = Me.cmbCategory)))"

    The title field is free text and the category and security are drop down items


    This is throwing all sorts of erros

    Help please
    Private Sub cmdSearch_Click()
    Me.Refresh
    Dim str As String

    str = "SELECT Notes.ID, Notes.[Expanded Number], Notes.Title, Notes.Date, Notes.[Security Level] FROM Notes WHERE ((((Notes.Title) Like '*" & Me.txtTitle & "*' )))"
    DoCmd.ApplyFilter str

    If Me.RecordsetClone.RecordCount = 0 Then
    MsgBox "No records match search", vbInformation, "Search Again"
    End If

    Me.txtTotal = Me.RecordsetClone.RecordCount
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You cant use form boxes in a query if there's nothing in them..so..
    Test all controls for a possible filter then build the where clause.

    Code:
    if not isnull(cboState) then   sWhere = sWhere & " and [state]='" & cboState & "'"
    if not IsNull(txtName) then    sWhere = sWhere & " and [Name]='" & txtName & "'"
    if not IsNull(chkContact) then sWhere = sWhere & " and [Contact]=" & chkContact.value
        'remove 1st And
    sWhere= mid(sWhere,4)
      'just use the filter
    me.filter = "select * from table where " & sWhere
    me.filterOn = true

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Be aware that "Date" is a reserved word in Access and shouldn't be used as an object name.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Rajeshsms,


    Tell us more about this database and the tables you have.
    What exactly --in simple plain English -- is the problem you are facing?

    There are many tutorials on youtube dealing with forms, queries.....

    you could look here.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 06-03-2014, 05:15 AM
  2. Replies: 7
    Last Post: 06-10-2013, 12:40 PM
  3. Replies: 2
    Last Post: 01-30-2013, 07:34 PM
  4. Replies: 3
    Last Post: 01-15-2013, 01:58 PM
  5. Replies: 7
    Last Post: 05-02-2012, 08:04 AM

Tags for this Thread

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