Results 1 to 5 of 5

Thread: Karl`s Tutorial 4

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Vancouver BC Canada
    Posts
    4

    Exclamation

    Hy all, I am having a difficult time with this code:Private Sub cmdFind_Click()

    Dim db As Database
    Dim rs As Recordset
    Dim SQLString As String

    Set db = OpenDatabase("c:\Nwind.mdb")

    SQLString = "SELECT Orders.CustomerID, " & _
    "Count(Orders.OrderID) " & _
    "AS NoOfOrders From Orders GROUP " & _
    "BY Orders.CustomerID " & _
    "HAVING (((Orders.CustomerID)='" & _
    txtCustID.Text & "'))"


    Set rs = db.OpenRecordset(SQLString)
    txtTotalNumber.Text = rs.Fields("NoOfOrders")

    SQLString = "SELECT Orders.CustomerID, " & _
    "Last(Orders.OrderDate) " & _
    "AS LastOrderDate From Orders GROUP " & _
    "BY Orders.CustomerID " & _
    "HAVING (((Orders.CustomerID)='" & _
    txtCustID.Text & "'))"

    >>>>MISMATCH ERROR Set rs = db.OpenRecordset(SQLString)

    txtLastDate.Text = rs.Fields("LastOrderDate")
    txtLastDate.Text = Format(txtLastDate.Text, "Long Date")

    rs.Close
    db.Close

    End Sub


    Can anybody see anything wrong? I keep coming up with a mismatch error.

    Thankyou for all your help

    James ( the newbie )

  2. #2
    Member
    Join Date
    Jun 2000
    Location
    Perth Western Australia
    Posts
    41

    Cool

    Apart from this line........

    >>>>MISMATCH ERROR Set rs = db.OpenRecordset(SQLString)

    which should be........

    Set rs = db.OpenRecordset(SQLString)

    I cannot see a lot else wrong.

  3. #3
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    It must be something in the SQL statement....Debug.Print the SQL statement before you do your Db.OpenRecordset

  4. #4
    Fanatic Member Gary.Lowe's Avatar
    Join Date
    May 2000
    Location
    In my sphere of influence
    Posts
    621

    Talking

    Check the values being entered into the table fields are the right type.

    i.e.
    you are not trying to put characters "abcdefg" into a filed that will only accept numeric "1234567"

    Also try checking the format the date is being sent to the database.

    Gary Lowe
    VB6 (Enterprise) SP5
    ADO 2.6
    SQL Server 7 SP3

    OK I know my spelling and grammer is crap so don't quote me on it!

    To err is human to take the P! is only natural !!

    Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip


  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Location
    Vancouver BC Canada
    Posts
    4
    Thankyou guys for the feedback. I will see if the data types are the same, however should it matter if you are only extracing values from a table? and not inserting?

    BTW the line with the >>>>Mismatch Error was put there so I could show you were the error is taking place.

    Thankyou for all your help!

    James Stenerson

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