Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't seem to refer to a combo box properly (Access2000)

    I open a form that has a dropdown where I select a school year. Then I click the Next button and I go to a form where I check off which fees I want on my report. When I've selected the fees, I click Done and it brings up a preview of my report. Something is going wrong with my school year dropdown in the first form. I just don't know how to refer to it in my query. I have a query that will list all the fees that I have checked off in the year I selected. But I just can't get the query to work. How do I include the school year I selected in my query?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't seem to refer to a combo box properly (Access2000)

    You don't have to include it in the query. Use the where condition of the docmd.openform.
    The code in the on click event of your next button should be something like this :
    <pre>Private Sub YourButton_Click()
    On Error GoTo Err_YourButton_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "YourFormName"

    stLinkCriteria = "[YourYearField]=" & "'" & Me![ComboBoxName] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_YourButton_Click:
    Exit Sub

    Err_YourButton_Click:
    MsgBox Err.Description
    Resume Exit_YourButton_Click

    End Sub</pre>

    Francois

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't seem to refer to a combo box properly (Access2000)

    Would I still do it that way? Because my first form frmChooseYear is just a blank form with a combo box that displays all the school years in my tblSchoolYear table. I have two fields in my tblSchoolYear: SchoolYearID, and SchoolYear. The combo box shows the SchoolYear field.

    When I click the Next button on my frmChooseYear, that opens another form frmSelectCategories that lists all the fees from my tblFees and a Select checkbox beside each fee. I check off which fees I want to show on my report, then I click my Done button on the frmSelectCategories form. Now the Category by Fee report opens up.

    The report prints out a list of each fee selected with a list of students' names under each fee showing how much of that fee that each student paid.

    I should be putting the code on the Done button that I press to open up the report, correct? So how do I write a Where condition when the SchoolYear is on the first form I open?

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Can't seem to refer to a combo box properly (Access2000)

    Try changing Francois's solution to:
    stLinkCriteria = "[SchoolYear]=" & Forms![frmChooseYear ]![ComboSchoolYear]

    I may not have the control names correct, so be sure to change those.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    284
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't seem to refer to a combo box properly (Access2000)

    But I would put the code on the Done button, right? (the one that I press to open up my report)

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Can't seem to refer to a combo box properly (Access2000)

    Why do you use two forms to get the selection ?
    Can't you put the year combobox on the category selection form? If this is a continuous form, you can put it in the header or the footer of the form.
    Use the same code to open your report but use DoCmd.OpenReport instead of DoCmd.OpenForm.
    Francois

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Can't seem to refer to a combo box properly (Access2000)

    You put it just prior to the DoCmd.OpenReport command, don't forget to put the stLinkCriteria in this command.

    I presume that the Done button is in the frmSelectCategories form.

Posting Permissions

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