|
本帖最后由 lms008 于 2018-6-22 11:24 编辑
在使用ADODB查询worksheet中的数据时,发现报错:""不是个有效名称。请确认它不包含无效的字符或者标,且名称不太长。
代码如下:
Function checkMobileHasExist(ByVal lonMobile As Long) As Boolean
Dim conn As Object, rsRecord As Object
Dim strSql As String, lMobileNo As Long
On Error GoTo errHandler
Set conn = CreateObject("ADODB.Connection")
Set rsRecord = CreateObject("ADODB.recordset")
lMobileNo = lonMobile
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
strSql = "SELECT COUNT(*) FROM [Master_list$] Where [Mobile No.]=" & lMobileNo & " AND [Serial number (ddmmyyyynnnn)] is not null "
rsRecord.Open strSql, conn ' adOpenKeyset, adLockOptimistic 1,3
If rsRecord(0) > 0 Then
checkMobileHasExist = True
Else
checkMobileHasExist = False
End If
Set rsRecord = Nothing
Set conn = Nothing
经过检查,所用的[Master_list 是存在的,在其他的function用类似的代码查询数据是不会报错的。急需高手指点具体哪里出现问题。
下面是 import的数据:
|
|