PDA

Click to See Complete Forum and Search --> : Karl`s Tutorial 4


JamesStenerson
Jul 19th, 2000, 03:13 PM
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 )

CGTS
Jul 20th, 2000, 01:05 AM
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.

Clunietp
Jul 20th, 2000, 10:04 AM
It must be something in the SQL statement....Debug.Print the SQL statement before you do your Db.OpenRecordset

Gary.Lowe
Jul 20th, 2000, 10:22 AM
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.

JamesStenerson
Jul 20th, 2000, 11:37 AM
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