Results 1 to 12 of 12
  1. #1
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291

    List box, row source, where syntax help needed

    Just need help with syntax of the Where statement:
    SELECT InspectionsDI.ID, InspectionsDI.[MN12] FROM InspectionsDI WHERE (need help here);

    I tested this code:
    Private Sub Form_Current()
    Dim var1 As String
    var1 = Me.Filter
    End Sub

    I put a watch on var1 and it was equal to: [Area] = 'GOL4'

    Some of the things I tried:
    WHERE InspectionsDI.[Forms!DIForm.filter]
    WHERE me.filter
    WHERE InspectionsDI.me.filter


    WHERE InspectionsDI. & [Forms!DIForm.filter]
    WHERE "InspectionsDI." & "[Forms!DIForm.filter]"
    WHERE InspectionsDI.[Forms!DIForm.filter]
    WHERE me!filter
    WHERE InspectionsDI!me.filter

    and I tried more things but obviously cant get the syntax of the where statement correct. Any help would be appreciated, thanks.

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    What is "Filter"? A form object? Also, your WHERE statement should be in the form of
    WHERE (something) (operator) (something)
    like
    WHERE name = "joe"
    or
    WHERE age < 25

    the syntax for passing in an object from a form is Forms!myFrm!myObj

  3. #3
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    See how I made var1 = me.filter This takes the value of Forms!DIForm.filter
    which is equal to: [Area] = 'GOL4' I am not sure if I can use that same syntax in the record source statement

    What I want my WHERE statement to be is
    WHERE InspectionsDI.[Area] = 'GOL4'

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    perhaps this will increase my understanding. Where is this SQL statement going to go?

  5. #5
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    A listbox on the form DIForm under the row source of the properties

    I have lots of row sources with similar code like this for a combo box
    SELECT [Cover/Frame Fit].[Cover/Frame Fit] FROM [Cover/Frame Fit] ORDER BY [Cover/Frame Fit].ID;

    I am just having a tough time with this WHERE statement because it is using the .filter control of the form

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    ahh ok. It's been a long day, I apologize for the confusion.
    I think what you would end up doing is creating a new variable to hold the entire WHERE clause to pass in instead of trying to concatenate it in SQL string. Also, I assume you are planning on doing this in VBA, because I dont know another way to do it.

    dim var2 as string
    dim runSQL as string

    var2 = "Inspection." & Me.Filter
    runSQL = "SELECT InspectionsDI.ID, InspectionsDI.[MN12] FROM InspectionsDI WHERE " & var2 & ";"

    see if that works. If not, I'm not sure how to proceed from there. Personally, I've never found myself trying to do what you're trying. It's a stab in the dark on my part.

  7. #7
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    I was hoping there was a way to do it without using VBA so it would update by itself but if VBA is the only way to do it I will just have to put in the form on current and some afterupdates

  8. #8
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    There very well may be a way to do it without VBA. I'm just not aware of one. Perhaps others can chime in. Hope it work sout for you though.

  9. #9
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    I made this work with VBA but before I mark solved just one last check anyone know how to do this with just Row Source Syntax?

  10. #10
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    This what I have done
    1) I have a form tabe1 with a combobox and a List box.
    2) I select a name in the combobox and it filters the form and the filter condition is also used in the query which the RowSource of the List Box


    Private Sub Combo13_AfterUpdate()
    Dim strSQl As String
    Dim strFilterCondition As String
    strFilterCondition = "[P_Name]='" & Combo13 & "'"
    DoCmd.ApplyFilter , strFilterCondition
    strSQl = "Select * From Table1 Where " & strFilterCondition
    Me.List11.RowSourceType = "Table/Query"
    Me.List11.RowSource = strSQl
    DoCmd.Requery "List11"
    End Sub

    I have used a string to hold the value of the filtercondition and passed the same on to the SQL that is to become the RowSource of the ListBox. The code is used in the after update event onf the combobox. refer to attached db.

  11. #11
    sesproul is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Posts
    50
    What is the purpose of this line:

    Code:
    DoCmd.ApplyFilter , strFilterCondition
    if you immediately apply the same selection criteria to the Me.List11.Rowsource? Does is limit all the other fields in the form?

  12. #12
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    DoCmd.ApplyFilter , strFilterCondition

    This is used to filter the form. You have got it Right. strFilterCondition is used to both to filter the form and as a criteria for the sql that populates the list box.

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

Similar Threads

  1. Maintenance on programs on open source
    By fsmikwen in forum Access
    Replies: 3
    Last Post: 01-15-2010, 08:43 AM
  2. if or syntax help needed
    By techexpressinc in forum Queries
    Replies: 16
    Last Post: 01-11-2010, 08:03 AM
  3. ComboBox Row Source Value
    By mpbertha in forum Forms
    Replies: 1
    Last Post: 08-21-2009, 06:34 AM
  4. Forms' Record Source
    By Progress2007 in forum Programming
    Replies: 11
    Last Post: 07-27-2009, 11:04 AM
  5. Control source and calculated values
    By meistersteff in forum Forms
    Replies: 0
    Last Post: 11-23-2007, 07:04 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