CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2014
    Posts
    2

    Query from multiple tables-Error

    Hi!

    I have a question about SQL query return data from multiple tables..

    Code:
    Private Sub Command1_Click()
    Dim psql
     cn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\Dictionary.mdb"
     cn.Open
      rs.Open "Select Spanish.*, English.* from Spanish, English", cn, adOpenDynamic, adLockOptimistic
    If Right$(Text2.Text, 2) = "ed" Then
    Text2.Text = Left$(Text2.Text, Len(Text2.Text) - 2)
         psql = "SELECT Spanish.Verbpast FROM English INNER JOIN Spanish ON English.Spsh_ID = Spanish.Spsh_ID WHERE English.Verbpresent= '" & Text2.Text & "'"
     rs.MoveFirst
        rs.Requery psql
    If Not rs.EOF Then
        Text3.Text = rs(“Verbpast”)
    End If
    End If
    End Sub
    The two tables are linked by the SpshId. . I want to get the past tense of a verb in Text3 if I type the past form of a verb. But I get ‘Type mismatch’ error.

    Can anybody help me on it?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Query from multiple tables-Error

    Use SQL MGMT STUDIO to debug query's. It stops at each word that faults, as apposed to the wrong line...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Query from multiple tables-Error

    Which line gives the error?

    There is no reason to select all records from the tables and then requery. You should get rid of the first query and use open on the other one.

    As for the type mismatch, that indicates that one of your variable types is incorrect. Is the ID in both tables the same type?

    Also note that while ed is common on past tense verbs there are also many that do not end in ed, such as ran, came, went, flew, drove and so on
    Always use [code][/code] tags when posting code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured