Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2003
    Posts
    56

    Question Unanswered: Filter on a form using two combo boxes

    Anyone have any idea's why I am getting a runtime error with this code?
    _________________________________________________
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmAllocation"

    If Not IsNull(Me!cboCompany) Then
    stLinkCriteria = "[CompanyID]=" & Me!cboCompany
    End If

    If Not IsNull(Me!cboYear) Then
    If Len(stLinkCriteria) <> 0 Then
    stLinkCriteria = stLinkCriteria & " AND "
    End If

    stLinkCriteria = stLinkCriteria & "[Year] = " & Me!cboYear
    End If

    DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria

    __________________________________________________ _

    When I click the button on my frmSelect, this code is supposed to pick up my criteria from two combo boxes and apply them the form called frmAllocation. However, it will not open the form - instead I get a message saying the following:
    Runtime Error 2501
    The OpenForm action was canceled

    Any idea's why this might be happening?

    C.

  2. #2
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    what data is in Me!cboCompany ie text, number

    if it's text try '"(single then double) & Me!cboCompany & "'(double then single)"
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  3. #3
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Originally posted by m.timoney
    what data is in Me!cboCompany ie text, number

    if it's text try '"(single then double) & Me!cboCompany & "'(double then single)"
    in fact before the open form command add the line

    debug.print stLinkCriteria

    then post the result here
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  4. #4
    Join Date
    Jan 2003
    Posts
    56
    Thanks,

    cboCompany is actually a number and cboYear refers to 1998,1999 etc etc.

    cboCompany gets is data from a table (tblCompany) and cboYear uses a Value list.

    Any ideas?!!


    C.

  5. #5
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Originally posted by coolowen
    Thanks,

    cboCompany is actually a number and cboYear refers to 1998,1999 etc etc.

    cboCompany gets is data from a table (tblCompany) and cboYear uses a Value list.

    Any ideas?!!


    C.
    try my second suggestion
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  6. #6
    Join Date
    Jan 2003
    Posts
    56
    Originally posted by m.timoney
    try my second suggestion

    I tried that but nothing happened when I executed the code.

    C.

  7. #7
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Originally posted by coolowen
    I tried that but nothing happened when I executed the code.

    C.
    have you got the immediate window open in the vb editor?

    if not press ctrl+G which should bring it up the debug.print will put the contents of the variable into the immediate window where you can just copy and paste in

    and if you still can't get it to work just put it in a msgbox and manualy transter the data
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  8. #8
    Join Date
    Jan 2003
    Posts
    56
    Originally posted by m.timoney
    have you got the immediate window open in the vb editor?

    if not press ctrl+G which should bring it up the debug.print will put the contents of the variable into the immediate window where you can just copy and paste in

    and if you still can't get it to work just put it in a msgbox and manualy transter the data
    Hi,
    Sorry about that.
    The contents are the following:

    [CompanyID]=7 AND [Year] = 1998

  9. #9
    Join Date
    Oct 2002
    Location
    Leicester - UK
    Posts
    820
    Originally posted by coolowen
    Hi,
    Sorry about that.
    The contents are the following:

    [CompanyID]=7 AND [Year] = 1998
    i've just tried that out on a dummy database and it worked so the problem must lie elsewhere

    if you email a zipped copy of your do to me, i'll see if i can find the problem my address is removed
    Last edited by m.timoney; 07-10-03 at 10:38.
    Definition of a Beginner, Someone who doesn't know the rules.

    Definition of an Expert, Someone who knows when to ignore the rules.

  10. #10
    Join Date
    Jan 2003
    Posts
    56
    Hi,

    Thanks for your help! I solved the problem. It was my own mistake, sorry for putting you to this trouble. I was not picking up the year value correctly - I was treating it as a number and it was a text value. In the immortal words of Homer Simpson - "Doh!".

    Sorry again & Thanks,

    C.

Posting Permissions

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