Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171

    Runtime Error 13 when filtering combobox

    I have two comboboxes on my form. They are both working correctly but I am getting a runtime error on the second box when a selection is made.

    The first combobox is Contract Number and should filter alone. The second combobox is Task Order and it's results are dependent on the selection made in the Contract Number.



    The Contract Number is filtering correctly but the Task Order combobox is getting a runtime error 13 Type mismatch.

    Any help would be greatly appreciated!

    Code:
    Private Sub cboContractNum_AfterUpdate()
         Me.Filter = "[ContractNum] = " & Chr(34) & Me.cboContractNum & Chr(34)
         Me.FilterOn = True
         Me.Requery
              
    End Sub
    Private Sub cboTO_AfterUpdate()
        Me.Filter = "[ContractNum] = " & Chr(34) & Me.cboContractNum & Chr(34) And "[TO] = " & Chr(34) & Me.cboTO & Chr(34)
         Me.FilterOn = True
         Me.Requery
    End Sub

  2. #2
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    can you show the SQL for the record source on the combo box with issue?

  3. #3
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Is Me.cboTO a text field?

  4. #4
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    SELECT DISTINCT tblPerfIssues.TO, tblPerfIssues.ContractNum FROM tblPerfIssues WHERE (((tblPerfIssues.ContractNum)=[Forms]![frmPerfLookup1]![cboContractNum]));

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Replace the CHR(34) with actual quotes, it would make it easier to read.

    Me.Filter = "[ContractNum] = " & Me.cboContractNum & " And [TO] = '" & Me.cboTO "'"

  6. #6
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    Now I get a Syntax error on this code.


    Me.Filter = "[ContractNum] = " & Me.cboContractNum & " And [TO] = '" & Me.cboTO "'"

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The above assumes that the first column in the row source of the contract number is a numeric field, and the first column of the TO row source is a text field. If this is not the case then changes need to be made as per adding/removing quotes.

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Oops, there is an "&" missing from the end of that statement - Me.cboTO & "'"

  9. #9
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    They are both text fields. What should the code look like? I get hung up with the quotes!

  10. #10
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Me.Filter = "[ContractNum] = '" & Me.cboContractNum & "' And [TO] = '" & Me.cboTO & "'"

  11. #11
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    Now when I run it when I select a contract number from the combobox it pops up a box with Enter Parameter Value for the contract number I selected.

  12. #12
    PinkLady50 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2017
    Posts
    171
    The debug is stopping on the Me.Requery line in the cboContractNum.

    Her is the revised code.

    Private Sub cboContractNum_AfterUpdate()
    Me.Filter = "[ContractNum] = " & "" & Me.cboContractNum & ""
    Me.FilterOn = True
    Me.Requery

    End Sub
    Private Sub cboTO_AfterUpdate()
    Me.Filter = "[ContractNum] = '" & Me.cboContractNum & "' And [TO] = '" & Me.cboTO & "'"
    Me.FilterOn = True
    Me.Requery
    End Sub

  13. #13
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    That could be from one of the row source queries. We/I have not touched that part of the design.

  14. #14
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Me.Filter = "[ContractNum] = '" & Me.cboContractNum & "'"

  15. #15
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Remember, text fields require quotes, numeric fields must not. When already inside a string, such as yours, the double-quote has been taken so you need to use single quotes. Surround the actual value with quotes for text fields.

    When in doubt, add Debug.Print statements
    Debug.Print Me.Filter
    Me.Filter="ContractNum='1234A'" will show
    ContractNum='1234A'

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-22-2015, 11:26 AM
  2. Replies: 2
    Last Post: 10-15-2014, 04:23 AM
  3. Replies: 1
    Last Post: 05-24-2014, 09:08 AM
  4. Replies: 13
    Last Post: 06-12-2012, 09:52 PM
  5. Replies: 5
    Last Post: 06-10-2011, 03:31 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