I've had the same trouble lately.
Microsoft has a couple of KB's on it.
Q209805 and
http://support.microsoft.com/default.aspx?scid=kb;en-us;257819
Well I solved my problem. I had copied the code from the web and it
had "Excel 9.0". I have WP2000 which requires "Excel 8.0".
The purpose of my exercise was to search an Excel range, looking for
one record (Part Number) and returning the Description from the cell
next to it.
After getting past the first error, I keep getting 'Syntax error
(missing operator) in query expression'.
After searching though some Access message boards, I discovered I had
to put the filter string (MyPartNum) in single quotes.
Sub TestGetDesc()
Call GetDesc("Widget1", "")
End Sub
Sub GetDesc(MyPartNum, MyDesc As String)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim NoOfRecords As Long
Dim SQLText As String
SQLText = "SELECT PART_NO, DESC FROM `MyInvRng`" _
& "WHERE PART_NO = '" & MyPartNum & '"
'MyPartNum is enclosed with double quote followed by a single quote
' Open the database
Set db = OpenDatabase("C:\My Documents\MyInv.xls", False, False, "Excel
8.0")
' Retrieve the recordset
Set rs = db.OpenRecordset(SQLText)
' Determine the number of retrieved records
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
'MsgBox (rs.RecordCount & vbCr & rs!PART_NO & " " & rs!Desc)
MyDesc = rs!Desc
'MsgBox (MyDesc)
' Cleanup
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
SG - 01 Jun 2005 17:02 GMT
Hi David,
I have the same code as you have now. The code works fine on some of the
PCs, that is strange. I cannot pass the first run time error even on my own
pc. It really bothers me. I tried a couple of solutions which were found on
the web, they didn't help. It happened lately like you said. I wonder if
something to do with windows update.
Can you tell me how you passed the first error?
Thanks,
Sarah
> Well I solved my problem. I had copied the code from the web and it
> had "Excel 9.0". I have WP2000 which requires "Excel 8.0".
[quoted text clipped - 51 lines]
>
> End Sub
SG - 01 Jun 2005 17:38 GMT
Hi David,
I fixed mine by changing the code to use ADO instead of DAO. Isn't that
strange?
Thanks for your help.
Sarah
> Well I solved my problem. I had copied the code from the web and it
> had "Excel 9.0". I have WP2000 which requires "Excel 8.0".
[quoted text clipped - 51 lines]
>
> End Sub
David Sisson - 01 Jun 2005 18:25 GMT
Is the DAO 3.6 reference still selected in your Tools> Reference?
SG - 01 Jun 2005 20:44 GMT
no, I removed DAO reference and use Active X..2.0 library. It works for me
now.
Sarah
> Is the DAO 3.6 reference still selected in your Tools> Reference?