I keep getting a Type Mismatch error when i run this recordset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James Blue
    New Member
    • Sep 2010
    • 1

    I keep getting a Type Mismatch error when i run this recordset

    Dim m_MeetingName, m_City, m_title As String
    Dim m_sql As Long
    Dim dbs As Database, rst, rst2 As Recordset
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecords et("Related Conference Categories", dbOpenTable)

    rst.MoveFirst
    Do Until rst.EOF
    m_City = "*"
    m_title = "*"
    m_MeetingName = rst("RelatedCon ference")
    MsgBox rst("RelatedCon ference")



    m_sql = "SELECT Count([Sourcecodes Test].ClientID) AS CountOfClientID FROM ([Related Conference Categories] INNER JOIN [Sources Test] ON [Related Conference Categories].RelatedConfere nce = [Sources Test].[Related Conferences]) INNER JOIN [Sourcecodes Test] ON [Sources Test].[Source Code] = [Sourcecodes Test].SourceCode WHERE ((([Sources Test].[Related Conferences]) '" & m_City & "' & '" & m_MeetingName & "' & '" & m_title & "' ));"
  • colintis
    Contributor
    • Mar 2010
    • 255

    #2
    Check the data type of your table if they are matching your vba codes or not, mostly this is cause by the variables compare to the table data types are not the same.

    Also, please use CODE TAGS ([CODE ] & [/ CODE]) when you are posting codes.

    Welcome to Bytes!

    Comment

    • OldBirdman
      Contributor
      • Mar 2007
      • 675

      #3
      I have NOT attempted to duplicate this situation or run the code. I have not tested my code. Without knowing where it fails, I do note the following:
      1) DIM Statements may not be correct. The statement
      Code:
      Dim m_MeetingName, m_City, m_title As String
      only declares m_title as String. The other two variables are Variant. This also occurs in another DIM Statement.

      2)
      Code:
      m_City = "*"
      m_title = "*"
      never change, and should be moved out of the Do Until ... loop

      3) The WHERE clause of the SQL assigned into m_sql seems to be wrong. If I assume [Related Conferences] has the value 'ABCDEFXYZ' and m_MeetingName the value 'CDE' then the WHERE clause is
      Code:
      ... WHERE (((ABCDEFXYZ) '* ' & ' CDE ' & '*' ))
      I think it should be more like
      Code:
      ... WHERE (('ABCDEFXYZ') LIKE '*CDE*'))
      which would be
      Code:
      m_sql = "... WHERE ((([Sources Test].[Related Conferences]) LIKE '*" & m_MeetingName & "*'));"
      in the m_sql = ... statement.

      Could you do a Debug.Print of m_sql or a MsgBox m_sql after the m_sql = "SELECT ...;" statement and post the result?

      Comment

      Working...