Results 1 to 4 of 4

Thread: Easy question. (Solved)

  1. #1

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Easy question. (Solved)

    Access:

    I need to populate a combobox with a field from my query. However I want the first row to be "Show All" and everything after that to be from my query.

    So I figure I need to put the results of my query into a string and append it to the end of my string that contains "Show All". Like this

    MyRowSourceString = "Show All;Item1;Item2;Item3..."

    Is there a way to do this?
    Last edited by Avatarp; Nov 11th, 2003 at 01:01 PM.

  2. #2
    Hyperactive Member
    Join Date
    May 2001
    Location
    Beirut, Lebanon
    Posts
    318
    I usualy use UNION.

    example, let's say that the field you want to populate is "Field1" from "Table1".
    VB Code:
    1. Combo1.RowSource = "Select ""(Show All)"" as Field1 From Table1 UNION Select Field1 From Table1"
    in order for the (Show All) item to show on the top of the list, I use "(".

  3. #3

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    There is an error somewhere in the syntax here?

    Code:
        cmboFlowMonth.RowSource = "SELECT ""(Show All)"" as SchedulerInputData.MonthEnd From SchedulerInputData UNION SchedulerInputData.MonthEnd From SchedulerInputData;"
    SchedulerInputData is my query
    MonthEnd is my field

  4. #4

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    I solved it....

    Set my combobox protery for RowSourceType to be "Value List"

    then I opened a recordset of my query and populated a string with any unique dtaes. like so:

    Code:
        Dim MyMonthString As String
        Dim MyDB As Database, rs As Recordset
        Set MyDB = DBEngine.Workspaces(0).Databases(0)
        Set rs = MyDB.OpenRecordset("SchedulerInputData", dbOpenDynaset)
    
        MyMonthString = "(All);"
        rs.MoveFirst
        Do While Not rs.EOF
            CurrentItem = CStr(Format(rs!monthEnd, "mmmm yyyy"))
            If InStr(MyMonthString, CurrentItem) = 0 Then
                MyMonthString = MyMonthString + CurrentItem + ";"
            End If
            rs.MoveNext
        Loop
        cmboFlowMonth.RowSource = MyMonthString

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