我在将报表数据库连接到iMacros宏以输入Web表单的vb脚本上收到错误。它与他们的站点(Database-2-Web Script)中的示例基本上是相同的代码,只是带有一些额外的字段。数据类型都是varchar。错误信息如下:
Script: C:\users\me\path\file.vbs
Line: 70
Char: 4
Error: Type mismatch: 'iimSet'
Code: 800A000D
Source: Microsoft VBScript runtime error
第70行,即:
iret = iim1.iimSet("RiskStatusReason", rs.fields(48))
我无法看到是什么让这条线变得特别。它和其他人一样,为什么这里的错误呢?任何VB专业人士都有这个答案吗?我是VBS的新手。
下面的完整代码(我添加了啦啦队消息):
Option Explicit
dim rs, iim1, sql
dim myname, mypath, connstring
dim iret
dim message
message = "This script reads data from a SQL Server database and submits this information to a web form."
message = message + " It reads from the database <database> and uses the macro <wsh-submit-2-web>." + vbCrLf + VbCrLf
message = message + "Tip: This script has the same function as <file-2-web-method2.vbs> but reads the data from a database instead of a text file." + vbCrLf + VbCrLf
message = message + "Tip: You're incredible, go get 'em tiger."
MsgBox (message)
'Note for x64 users: You must start the VBS script in 32bit mode (C:\Windows\SysWOW64\wscript.exe) for the Microsoft ODBC Driver to work
'Please see the note about VBS scripts on http://wiki.imacros.net/x64 for more details
' find current folder
myname = WScript.ScriptFullName
mypath = Left(myname, InstrRev(myname, "\"))
' open ACCESS database
set rs = CreateObject("ADODB.Connection")
'connstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & mypath & "IIM-TEST-SUBMIT.MDB"
'NOTE: To open an SQL database instead of an ACCESS database please use:
'
connstring = "driver={SQL Server};server=server\server1;uid=user;pwd=password;database=database"
'
rs.Open (connstring)
' use SQL to select information
sql = "select * from _Temp"
set rs = rs.Execute(sql)
set iim1= CreateObject ("imacros")
iret = iim1.iimOpen("")
iret = iim1.iimDisplay("Submitting Data from SQL Server")
do until rs.eof
'Set the variable
iret = iim1.iimSet("AccountingName", rs.fields(9))
iret = iim1.iimSet("ReportFileDate", rs.fields(8))
iret = iim1.iimSet("LastWeekStatus", rs.fields(31))
iret = iim1.iimSet("CurrentStatus", rs.fields(32))
iret = iim1.iimSet("TrendingStatus", rs.fields(33))
iret = iim1.iimSet("Headline", rs.fields(28))
iret = iim1.iimSet("CostStatus", rs.fields(34))
iret = iim1.iimSet("CostStatusReason", rs.fields(43))
iret = iim1.iimSet("ScheduleStatus", rs.fields(35))
iret = iim1.iimSet("ScheduleStatusReason", rs.fields(44))
iret = iim1.iimSet("ScopeStatus", rs.fields(36))
iret = iim1.iimSet("ScopeStatusReason", rs.fields(45))
iret = iim1.iimSet("TMStatus", rs.fields(37))
iret = iim1.iimSet("TMStatusReason", rs.fields(46))
iret = iim1.iimSet("ResourceStatus", rs.fields(38))
iret = iim1.iimSet("ResourceStatusReason", rs.fields(47))
iret = iim1.iimSet("RiskStatus", rs.fields(39))
iret = iim1.iimSet("RiskStatusReason", rs.fields(48))
iret = iim1.iimSet("BenefitsStatus", rs.fields(40))
iret = iim1.iimSet("BenefitsStatusReason", rs.fields(49))
iret = iim1.iimSet("QualityStatus", rs.fields(41))
iret = iim1.iimSet("QualityStatusReason", rs.fields(50))
iret = iim1.iimSet("Filename", rs.fields(2))
iret = iim1.iimPlay(mypath & "Macros\_SRfromSQL.iim")
If iret < 0 Then
MsgBox "Error code: "+cstr(iret) + VbCrLf + "Error Text: "+iim1.iimGetErrorText()
End If
rs.movenext
loop
iret = iim1.iimDisplay("Done!")
iret = iim1.iimClose
WScript.Quit(iret)