Results 1 to 9 of 9
  1. #1
    Join Date
    May 2004
    Posts
    55

    Unanswered: Row Source for a listbox

    Check out the date add function.

    Here is an example for a listbox to add 15 min incriments 16 times
    Private Sub loadDates()
    Dim source As String
    Dim tme As Date
    Dim i, j As Integer

    tme = Format(#1/1/2004 12:00:00 PM#, "mm/dd/yyyy hh:nn")
    source = tme

    For i = 0 To 15
    tme = DateAdd("n", 15, tme)
    source = source & ";" & tme
    Next i

    Me.List0.RowSource = source
    End Sub


    How do I use the above function as the record source for my list box?? I am confused...

    Thanks,
    Dharmesh

  2. #2
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Make sure that value for the string (source) is correct after the loop,
    e.g. "First; Second; Third;"

    Also, did you set the Row Source Type property of your listbox to Value List?
    You can find it under the Data tab of the properties window.
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

  3. #3
    Join Date
    Dec 2003
    Posts
    268

    Load Event

    Wow, this code looks familiar......

    Anyhoo. Add the sub routine to the the code for the form. Then on the load event for the form call the function. Ta dah......

    Like I said in the previous post, you are gonna have to tweak the code to be able to make the increments in the fashion that you want.

    MW

  4. #4
    Join Date
    May 2004
    Posts
    55
    Quote Originally Posted by mjweyland
    Wow, this code looks familiar......

    Anyhoo. Add the sub routine to the the code for the form. Then on the load event for the form call the function. Ta dah......

    Like I said in the previous post, you are gonna have to tweak the code to be able to make the increments in the fashion that you want.

    MW
    MW
    i added row source as value list and on the load event for the form called the function. But it still doesn't work.. what goes in the row source or control source of the listbox...

    Private Sub HISTORY_Load()
    Dim source As String
    Dim tme As Date
    Dim i, j As Integer

    tme = Format(#1/1/2004 12:00:00 PM#, "mm/dd/yyyy hh:nn")
    source = tme

    For i = 0 To 15
    tme = DateAdd("n", 15, tme)
    source = source & ";" & tme
    Next i

    Me.List0.RowSource = source
    End Sub

  5. #5
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Code:
    Me.List0.RowSource = source
    That is the code that sets the Row Source of a listbox named List0 to equal to the string source.

    Have you gone into the debg window an run through the code line by line? What is source equal to after the loop finishes? Try adding
    Code:
    msgbox source
    after the loop so you can see what source is equal to after the loop finishes without having to run through the code.

    The code looks good to me. You might want to add the following as the last line.
    Code:
    me.List0.refresh
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

  6. #6
    Join Date
    May 2004
    Posts
    55
    Quote Originally Posted by Cosmos75
    Code:
    Me.List0.RowSource = source
    That is the code that sets the Row Source of a listbox named List0 to equal to the string source.

    Have you gone into the debg window an run through the code line by line? What is source equal to after the loop finishes? Try adding
    Code:
    msgbox source
    after the loop so you can see what source is equal to after the loop finishes without having to run through the code.

    The code looks good to me. You might want to add the following as the last line.
    Code:
    me.List0.refresh
    Private Sub HISTORY_Load()
    Dim source As String
    Dim tme As Date
    Dim i, j As Integer

    tme = Format(#1/1/2004 12:00:00 PM#, "mm/dd/yyyy hh:nn")
    source = tme

    For i = 0 To 15
    tme = DateAdd("n", 15, tme)
    source = source & ";" & tme
    MsgBox " '" & source & "' "
    Next i

    Me.List0.RowSource = source


    End Sub

    I don't know how to debug. What do I click under the debug window. I tried add watch and other things but nothing worked.

    Also, when I use Me.List0.RowSource = source would it show up on the Rowsource of the listbox because in this it does not. There is no rowsource for the ListBox0 on the form.

  7. #7
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Here is a sample. Whe the form, frm1, the Open event of the form sets the row source for the listbox, List0. Clicking the button labeled "Change" will change the row source date.

    Hope this helps!
    Attached Files Attached Files
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

  8. #8
    Join Date
    May 2004
    Posts
    55
    Quote Originally Posted by Cosmos75
    Here is a sample. Whe the form, frm1, the Open event of the form sets the row source for the listbox, List0. Clicking the button labeled "Change" will change the row source date.

    Hope this helps!

    That helps..but i just realized that since this is a date list it is better to use a combobox. So I used a combo box on my form. What do I have to change in order to gt a combobox working?

  9. #9
    Join Date
    Apr 2003
    Location
    Alabama, USA
    Posts
    154
    Quote Originally Posted by dmesh
    What do I have to change in order to gt a combobox working?
    Change the name of the control from that of the listbox to the name of the combobox.
    Code:
    Me.List0.RowSource = source
    http://AccessDB.Info

    You live and learn. At any rate, you live. - Douglas Adams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •