Question Locked

how to execute insert query inVB Script

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

i have written a the follwing code in vb script

and it shows the Error "too few parameter expected 1 80040E10

how ever this code when written in VB run smoothly

' open database
dim i
dim filename
dim RNO
dim restno
dim f
i=1

Set con = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
set rs = CreateObject("ADODB.Connection")
set rst=CreateObject("ADODB.Connection")

con.Open "DBQ=C:\iMacro\datasource\testDB.mdb;" & "DRIVER={Microsoft Access Driver (*.mdb)};"

rs.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\iMacro\datasource\testDB.mdb")
rst.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\iMacro\datasource\testDB.mdb")

' use SQL to select information
sql = "select * from [iMacros-01]"
set rs = rs.Execute(sql)

do until rs.eof
'Set the variable
rtno=1

restno="Mohan Das Karam Chand Gandhi" f = Split(restno, " ")

If UBound(f) > 4 Then
If LCase(f(5)) = "about" Then
rtNo = f(6)
Else
rtNo = f(5)
End If
Else
rtNo = 0
End If

fname = "#c:\imacro\extract\" & rs.Fields(0) & "+" & rs.Fields(1) & "+" & rs.Fields(2) & "+" & i & ".htm#"

isql = "insert into GoogleQuery values (" & rs.Fields(0) & "," & Chr(34) & rs.Fields(3) & Chr(34) & "," & rtNo & "," & Chr(39) & fname & Chr(39) & ")"

i = i + 1

cmd.CommandText = ISQL
'cmd.CommandType = adCmdText
Set cmd.ActiveConnection = con
inputbox "","",cmd.commandtext
k= cmd.Execute
msgbox(isql)
rs.movenext
loop
iret = iim1.iimDisplay("Done!")
iret = iim1.iimExit
WScript.Quit(0)

3 replies

by pantera4life00

It looks like you accidentally deleted a return on this line:

restno="Mohan Das Karam Chand Gandhi" f = Split(restno, " ")
should be 2 seperate lines:
restno="Mohan Das Karam Chand Gandhi"
f = Split(restno, " ")

Other than that I noticed you use variables to hold 2 different types of objects sometimes. It wouldn't cause an error in a script but I would think that it would in vb. You probably don't have Option Explicit specified in vb. That's always a good idea.

For instance, the line that reads:
set rs = rs.Execute(sql)
rs is a connection but rs.execute would return a recordset. So at this point rs goes from being a connection to a recordset. I would use another variable:
dim rsResult
set rsResult = CreateObject("ADODB.Recordset")

Then use:
rsResult = rs.Execute(sql)
instead of
rs = rs.Execute(sql)

It wouldn't cause an error but your also not declaring a few variables.

by sitanshuwesley

Thanku for your valua ble suggestion
and i will give u trouble time to time

This discussion is closed to new replies.