OpenRecordSet error Type Mismatch! How to solve this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mutanic
    New Member
    • Oct 2010
    • 19

    OpenRecordSet error Type Mismatch! How to solve this?

    Hi everybody, I couldn't identify what is the error...here is my code :

    Code:
    Public Sub cmdSelRO_Click()
    On Error GoTo Err_cmdSelRO_Click
    
    Dim dbs As Database
    Dim rst As DAO.Recordset
    Dim SQL As String
    
    SQL = "SELECT * FROM tblSolicitorMonthlyReport WHERE RO = '" & cmbRO.Value & "' ORDER BY RO"
    Set dbs = CurrentDb("tblSolicitorMonthlyReport")
    Set rst = dbs.OpenRecordset(SQL, dbOpenTable)
    rst.MoveLast
    
    Exit_cmdSelRO_Click:
        Exit Sub
    
    Err_cmdSelRO_Click:
        MsgBox Err.Description
        Resume Exit_cmdSelRO_Click
        
    End Sub
  • Mariostg
    Contributor
    • Sep 2010
    • 332

    #2
    If the value of cmbRO.Value is numeric, remove the single quotes surrouding your query statement.

    Comment

    • prasad599
      New Member
      • Feb 2009
      • 24

      #3
      what is the datatype of RO in the database ?

      Comment

      • mutanic
        New Member
        • Oct 2010
        • 19

        #4
        Ok, I just change the code into this :

        Code:
        Public Sub cmdSelRO_Click()
        On Error GoTo Err_cmdSelRO_Click
        
        Dim dbs As Database
        Dim rst As DAO.Recordset
        Dim SQL As String
        
        'If txtTitleRecoveryOfficer.Visible = False Then
        '    txtTitleSolicitor.Visible = True
        'Else
        '    txtTitleRecoveryOfficer.Visible = False
        '    txtTitleSolicitor.Visible = True
        'End If
        
        Set dbs = CurrentDb()
        Set rst = dbs.OpenRecordset("SELECT * FROM tblSolicitorMonthlyReport WHERE RO = '" & cmbRO.Value & "' ORDER BY RO", dbOpenDynaset)
        rst.MoveLast
        
        Exit_cmdSelRO_Click:
            Exit Sub
        
        Err_cmdSelRO_Click:
            MsgBox Err.Description
            Resume Exit_cmdSelRO_Click
            
        End Sub
        but nothing happen...??? I wanted to change the recordset inside my form base on my selection... I select any "Recovery Officer" name from dropdownlist and it suppose to change my current recordset which it only contain data related to selected name. How do I solve this???

        Comment

        • mutanic
          New Member
          • Oct 2010
          • 19

          #5
          Data type of RO is "Text" only...

          I got list of "Recovery Officer" inside table tblRO which is connected to tblSolicitorMon thlyReport as it would appear as dropdownlist when you open in table mode.

          Now I got this button in form which also contain list of "Recovery Officer" as dropdownlist, I select the name then I want my form recordset contain related data to the selected name. How do I do this?

          Comment

          • Mariostg
            Contributor
            • Sep 2010
            • 332

            #6
            Not sure I see clearly what you try to achieve. But if you want to change the content of your form when the combo content change, the form has to know the dataset has changed.

            So on an On update event of the combo box, you want something like
            Code:
            MyForm.Recordsource=YourSqlQuery

            Comment

            • prasad599
              New Member
              • Feb 2009
              • 24

              #7
              try cmbRO.text instead of cmbRO.Value

              Comment

              Working...